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

Partial with a possible argument #408

Open
moseleyi opened this issue Nov 12, 2022 · 0 comments
Open

Partial with a possible argument #408

moseleyi opened this issue Nov 12, 2022 · 0 comments

Comments

@moseleyi
Copy link

I've started implementing Moustache in a sample project to see if it would help me with flexibility when it comes to templates.

I have a file called top.php that has the following:

<div id="top">
   {{> navigation }}
</div>

Navigation in PHP is an array as there can be multiple navigations, it would look like this:

$data = [
  "navigation" => [
    "main" => HTML_HERE,
    "left" => HTML_HERE
  ]
];

How can I make it configurable to only render "main" or "left"? I tried the following:

<div id="top">
  {{> #navigation }}
    {{ main }}
  {{> /navigation }}
</div>

And then I have the navigation partial:

<div class="navigation">
  {{ }}
</div>

but I'm not sure how to get it to work. The navigation.moustache should be a reusable HTML but I only want to display one at the time. This is an example html I would like:

<div id="top">
  <div class="navigation">
    MAIN NAVIGATION
  </div>
</div>
<div id="content">
  <div>
    <div class="navigation">
      LEFT NAVIGATION
    </div>
  </div>
</div>
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

1 participant