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.
Related
I have a partial view with a script I want to include in all my views, I dont't wanna #include this partial in all my layouts and blade views but instead add it to all rendered views, my partial looks like this:
<script type="text/javascript">window.$app = {!! json_encode(app(App\Helpers\Javascript::class)->app) !!};</script>
How can I do this?
You could:
include it in your main(s) layout template (the one(s) handling <html> and <body> tags)
you could use a Laravel View Composer to add the JSON data to the required views. Those views would so include the JSONed data, that you'd echo in the right place to be handled by your JS.
you could check the Php-Vars-To-Js package that allows you to put some data from PHP in a custom JS namespace (eg window.yourNameSpace). And then use it from a View Composer or the specific controller's methods concerned by your views.
Im new to October CMS
I read the documentation and its states that components can be used inside a layout on the PHP Section (https://octobercms.com/docs/cms/layouts)
i want to create a component that will be used as configuration file for my theme, declaring global variables, that will be used on all pages, but will also be used for all layouts i will create. but i cant find how to do it via code. Like include a file. i want this to used this parameters inside the PHP Section of the layout and the pages.
If components is not the best way, can you ppl sugest me what is the best way
I did before search a lot to find some way that I can share variables to all my layouts and pages but couldn't find anything.
So I tried my own trick and it worked.
In your frontend you must have header.htm partial. so in the code section in it write a onStart() function and set your global variables so you can access them from any layout or page which includes the header partial.
For example in your header.htm code section:
function onStart() {
$this['my_var'] = ['name' => 'Ahmed', 'age' => 17];
}
That way you can access my_var variable wherever you want in all your layouts and pages which header.htm partial is included.
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));
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 use a basic setup which uses a layout.phtml for the HTML Layout and view scripts for the content part.
I want to control some variables in the layout in my controllers, i.e. the title of my site.
How can I access my layout to output variables from within the controller?
Thanks for your feedback!
Anything you assign to view in your controllers will be accessible both in view scripts and layout scripts - they use the same Zend_View.
As for setting the title of the page, simply use the HeadTitle view helper http://framework.zend.com/manual/en/zend.view.helpers.html#zend.view.helpers.initial.headtitle
$myLayout = Zend_Layout::getMvcInstance()->getView();
$myLayout->var = 'foo:bar';
in layout.phtml:
echo $this->layout()->var;