Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Confused by how to make page specific variables available #308

Open
paxperscientiam opened this issue Jan 20, 2017 · 1 comment
Open

Confused by how to make page specific variables available #308

paxperscientiam opened this issue Jan 20, 2017 · 1 comment

Comments

@paxperscientiam
Copy link

paxperscientiam commented Jan 20, 2017

Hello @bobthecow

I'm new to templating and there's something that is throwing me.

Previous, I set page specific data in a view (home.php,about.php,etc). Each page would include a partial like "head.php". When "head.php" was included, it would have access to said data.

Using Mustache, there doesn't seem to be to define page-specific variables without having to define a route for each individual page/view/whatever.

Am I missing something?

Thanks.

EDIT:

The solution I've come up with is to store page-specific data as custom attributes on elements, then to grab them with DomDomdocument, then work that into Mustache.

@BlackScorp
Copy link

BlackScorp commented Dec 12, 2017

Hello @paxperscientiam

You can define a layout in mustache and add blocks there, in your specific template then you can define what ever you like.

Example:
lets say you create a mainLayout.mustache with following Code https://pastebin.com/f5kFVkcn
Then you have lets say on the main page different header image than on contact.

then your index.mustache might look like this https://pastebin.com/UUneii6D while your contact page would look like this https://pastebin.com/B2aYxgfx

So you can define Layouts and define placeholders in the layout, e.g. content, title, stylesheets etc. Then in your template you define which layout should be used and inside the template you define the content for the placeholders.

ofc you can even create partials within placeholders https://pastebin.com/Am2gpk0k

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants