views:

72

answers:

2

Hi guys, I have a question regarding the view.yml file in Symfony. Basically I would like to be able to include certain javascript SDKs in my layout with the help of the view.yml file like so:

first i would add an entry the the corresponding view file:

all:
  load_facebook: true
  load_twitter: true
  stylesheets:    
  javascripts:  

and then in the layout do something like:

<?php if (sfConfig::get('view_load_facebook', true)): ?>
          <div id="fb-root"></div>
          <script type="text/javascript">
            window.fbAsyncInit = function() {
              FB.init({
                appId: '<?php echo sfConfig::get('app_facebook_comment_app_id') ?>',
                status: true,
                cookie: true,
                xfbml: true
              });
            };
            (function() {
              var e = document.createElement('script'); e.async = true;
              e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
              document.getElementById('fb-root').appendChild(e);
            }());
          </script>          
<?php endif; ?>

Unfortunately I am unable to get the option with sfConfig::get('view_load_facebook') thus I'm guessing they have never been loaded. Has anyone got something like this to work? I think it would be a very good idea to have this option in the view.yml file as it would be very easy implement and very flexible.

Thanks,

Vince

+1  A: 

You can store your custom settings in app.yml file:

all:
  load_facebook: true
  load_twitter: true 

and refer to then with sfConfig::get(app_load_facebook)

Dziamid
@Vincent: I think this is the way to do it. Your current code is referring to the app.yml file already, with the "app" at the beginning of the configuration you're calling.
Tom
Yes, that would be an alternative however it is far too inflexible. I need to set the 3rd party sdk on a template basis or at least on a module basis. This would indeed also be possible in the app.yml file by holding an array of modules for which to enable the sdks however I feel that this approach is very unintuitive and not really the right place to put this information.
vincent
A: 

Can't you create an app.yml file inside the module directory? Anyway I don't know whether that would be a good solution.
Alternatively you may use slots.
Or maybe, even better, put all the code of the SDK in a JS file and insert that in the view.yml

Tom