I have a base twig template that is being extended by all the user twig templates, I have a main navigation in the base template that contains the profpic of the user, I want to pass the profpic variable to base template while rendering the index template of user via same controller.. how do I do this?
Please help..
You want make that ?
$html = $this->renderView('AccueilBundle:Reservation:billet.html.twig', array(
'reservation' => $reservation));
Related
I want to create custom from my module to controller new page but have some variable to send with. I not to want to show like this http://website.com/en/modelurl?id=17. i want to route like this http://website.com/en/modelurl/17. and i create like from my model class and past it to smarty template
$this->smarty->assign(array(
'getlink' => $this->context->link->getModuleLink('tmmanufacturerblock','display'),
));.
smarty template link: <a href="{$getlink}?id={$variable}">.
So how can i create clean url Like this:http://website.com/en/modelurl/17
i am currently working on a symfony project,
what i have:
app/Resources/views/mytemplate/
the folder mytemplate contains all of the important twig-views for my web app.
My question is, is there any possibility that third party members can create their own templates which override my "mytemplate" without creating controllers pointing to them ?
Like:
i have this template:
app/Resources/views/mytemplate/home/index.html.twig
An other person could create a new template in the same views directory like:
app/Resources/views/thirdparty/home/index.html.twig
to override my template.
is there any possibilty like this?
Greetings!
Well, to me, you have two possibilities :
The template that you want to be able to be redefined is the one specified with the method renderView() or similar in your controller : in this case, the possibilities are limitless. It's up to you to define the logic layer determining which template has to be rendered. You could for example force the user redefining the template to name it with a specific additional pattern, and then parse the right template to use thanks to a method inherited in all your controllers.
$content = $this->renderView(
$this->getInheritedTemplate('AcmeHelloBundle:Hello:index.html.twig'),
array('name' => $name)
);
The template that has to be redefined is one inherited in another twig template : In this case, it's almost the same. You could imagine writing your own Twig filter/function in order to retrieve the right template. The code should be very similar to the first case.
Hope this helped.
I'm trying to make a template with mustache.
layout.mustache
-- view/page1.mustache
-- view/page2.mustache
-- view/page3.mustache
I set my loader as layout.mustache and my partials as view directory.
Until this it's ok.
Based on the followed hierarchy I'm trying to load a view in my main layout with something like
$m->render('layout', array('page' => 'page1'));
and in my layout {{> page}} it's not working. It's returning "page1" it's not loading the mustache file...
I'm a new user in lesslogic template so I need your help... Maybe what i'm trying to do its not possible.
Thanks your for your future help.
If Mustache supported such a thing, it would look like {{> {{page}} }}, because what you're saying is not "load the page template", but "load the template named (value of page variable)". That's very much on the "logic" side of the line, so it's not something Mustache supports.
That said, you can do what you want to do, you just have to get a little creative :)
You can hijack Mustache's partials loader with something like the filesystem alias loader here.
Then you'd instantiate Mustache with that as a partials loader:
$m = new Mustache_Engine(array(
'partials_loader' => FilesystemAliasLoader('path/to/views')
));
Now, just before you render, you would set an alias for the page partial:
$m->getPartialsLoader()->setTemplate('page', 'page1');
$m->render('layout', $data);
When Mustache gets to your {{> page }} partial, it asks the FilesystemAliasLoader to load up "page". It looks up "page" in its aliases, and decides you meant "page1", and loads view/page1.mustache instead.
I'm using silex with a legacy application with a lot of smarty templates and also want to use the Form Provider, but the documentation has only an example to use this with Twig.
Does anyone has a small example how to render the Form to a variable that can then be displayed in a smarty template
my understanding is, that you can not render a form only by the symfony form classes.
Those classes do not have the functionality to render the form.
You need some templates that do the rendering. Those templates can be PHP or Twig.
Here is a example how to get the Form as HTML which you could then pass to the smarty template:
$html .= $silex['twig']->render('template.twig', array(
'form' => $form->createView
));
$smarty->assign('form_html',$html);
I can't understand when to use Layout's variables and when to use View's variables to get page segments on the page. Here is the picture form their Layout package tutorial ($this means the View instance everywhere):
Why Navigation, Content and Sidebar segments are got as Layout variables?
$this->layout()->nav;
But HeadTitle, HeadScript, HeadStylesheet are got straightly from View?
$this->headTitle(); // I know that this is a placeholder view helper.
// But this segment of the page logically belongs to Layout.
// and it has to be called smth like view->layout->placeholder
And why Header and Footer are from some partial method of the View but not Layout's properties?
$this->partial('header.phtml');
I've tried to change them and both ways work fine:
echo $this->nav; // I assigned navigation segment script to the View and it works;
I tried to assign Footer segment script to the Layout and it also works:
$layout->footer = $footer;
echo $this->layout()->footer; // it also works, it's displayed on the page
Any of the ways may be applied to any variable on the page. For example in Navigation segment I have a lot of variables to display and I can output them using both ways - one variable as Layout's property, another one sa View's property.
So what is the rule to use them right way? When should I use View's variables and when Layout's ones?
I agree that this isn't very clear from the documentation, and I don't think $this->layout()->nav is explained at all. A few points that might help:
$this->layout() is actually a call to the layout view helper, which returns the current instance of Zend_Layout.
Zend_Layout registers its own placeholder helper (with the key 'Zend_Layout'), and by default creates a 'content' variable in this.
the Zend_Layout class has a magic __get() method which proxies any member variable calls over to its registered placeholder container. So calling $this->layout()->content is another way of writing $this->placeholder('Zend_Layout')->content
the Zend_Layout class also has a magic __set() method that proxies stored data to the placeholder class. So $layout->footer = 'foo' is the same as calling $this->placeholder('Zend_Layout')->footer = 'foo' in the view
With that in mind:
Why Navigation, Content and Sidebar segments are got as Layout variables?
As these are accessing data stored in Zend_Layout's placeholder. You could also use $this->placeholder('Zend_Layout')->content
But HeadTitle, HeadScript, HeadStylesheet are got straightly from View?
These are view helpers.
And why Header and Footer are from some partial method of the View but not Layout's properties?
This is the standard way of accessing content from other templates.
In general, assume that using the view object is the correct way to access the data. Use the layout object/helper only if you know the data is in the layout placeholder.
The advantage of using placeholders over partials is that you can access and modify them in several different places, including in the view itself. For example say you had a sidebar which is stored in a partial. If you were to store this in the Zend_Layout placeholder instead (for example in a controller plugin), you can then override this for certain actions in the controller:
public function someAction()
{
$this->view->layout()->sidebar = 'Some other sidebar content';
}
or in the view script itself:
<?php $this->layout()->sidebar = 'Content for this page only'; ?>