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 optio开发者_开发百科n 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
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)
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
精彩评论