Conditional rendering of flat navigation

Conditional rendering of flat navigation

by Roshan Raj -
Number of replies: 1

I made some changes in the columns2.php file and created a new node and i am passing it in $flat->coursetext to my flat-navigation.mustache.

here  i want the normal {{text}} to render on main page, whereas on the courses page ONLY {{coursetext}} should render. how do i make this condition in mustache ?

Average of ratings: -
In reply to Roshan Raj

Re: Conditional rendering of flat navigation

by Andreas Grabs -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Translators

Hi Roshan,

you only can check your elements whether or not they are not empty. If your mentioned variables only exist when they should be used it could look like this:
{{#text}}{{.}}{{/text}}{{#coursetext}}{{.}}{{/coursetext}}

But in fact it is the same as: {{text}}{{coursetext}} because mustache checks the output by itself.

If you have another control variable like "ismainpage" you might use this:
{{#ismainpage}}{{text}}{{/ismainpage}}{{^ismainpage}}{{coursetext}}{{/ismainpage}}

Best regards
Andreas