tooth-paste Posted February 15, 2017 Share Posted February 15, 2017 I build a single template. Several Tag pages in the Admin use this template. Every page has a different menu. I try to output a different menu by placing a piece of code in the Fieldtype Textarea. The markup shows in the source code in the browser but is not generating any menu. Is the Fieldtype Textarea suitable to place code in? Link to comment Share on other sites More sharing options...
LostKobrakai Posted February 15, 2017 Share Posted February 15, 2017 It is, but it's not adviced to do so, because of the security risks involved. E.g. Ryan did recently move the php code for page fields out of the backend and replaced it with telling people to use hooks. But to run arbitrary php code look at eval(). 1 Link to comment Share on other sites More sharing options...
kongondo Posted February 15, 2017 Share Posted February 15, 2017 Do you really need to generate menus in the text area? Why not in the pages' template files? 1 Link to comment Share on other sites More sharing options...
tooth-paste Posted February 15, 2017 Author Share Posted February 15, 2017 3 hours ago, kongondo said: Do you really need to generate menus in the text area? Why not in the pages' template files? You mean to make a separate template for every single Tag? Link to comment Share on other sites More sharing options...
kongondo Posted February 15, 2017 Share Posted February 15, 2017 1 hour ago, tooth-paste said: You mean to make a separate template for every single Tag? No. I am looking at this: 6 hours ago, tooth-paste said: Every page has a different menu. From your code, it seems the 'difference' is based on these pages' children? You can output the menus in the single template file based on the page that is being viewed...i.e. $page->children; Maybe I am missing something? Link to comment Share on other sites More sharing options...
tooth-paste Posted February 15, 2017 Author Share Posted February 15, 2017 The tree of pages are filter items (page reference). Every selection outputs a different menu. At this point I have a template file for every filter-option. It is not the most ideal solution but don't know how to do it differently. Link to comment Share on other sites More sharing options...
kongondo Posted February 15, 2017 Share Posted February 15, 2017 To be honest, am totally clueless. I don't still get the reason why you should have code in your editor. Maybe if we saw a page tree and a bit more clarification we'd be able to advise better. 1 Link to comment Share on other sites More sharing options...
tooth-paste Posted February 16, 2017 Author Share Posted February 16, 2017 Within the coach page I made a Page Reference (checkboxes) to filter coaches. My tree looks like this: Coaches -Coach 1 -Coach 2 etc. This is how my references tree looks like: Provinces: -Limburg -Drenthe -Utrecht etc. The reason why I wanted to place code in my editorial that I wanted to use one template for my references. Now I have made the templates Limburg.php, drenthe.php and so on. The code for every reference, and the one that changes is on every template is: <div class="row"> <?php $coaches = $pages->find("coach_provincie=Limburg"); foreach ($coaches as $coach) { echo '<div class="col-md-6"><a href="'. $coach->url .'">'. $coach->title .'</a></div><div class="col-md-6">'. $coach->coach_locatie .'</div>'; } ?> </div> Link to comment Share on other sites More sharing options...
LostKobrakai Posted February 16, 2017 Share Posted February 16, 2017 <div class="row"> <?php $coaches = $pages->find("coach_provincie=$page->title"); foreach ($coaches as $coach) { echo '<div class="col-md-6"><a href="'. $coach->url .'">'. $coach->title .'</a></div><div class="col-md-6">'. $coach->coach_locatie .'</div>'; } ?> </div> What about that? 1 Link to comment Share on other sites More sharing options...
tooth-paste Posted February 16, 2017 Author Share Posted February 16, 2017 @kongondo, @LostKobrakai: Thank guys! Works great! Link to comment Share on other sites More sharing options...
kongondo Posted February 16, 2017 Share Posted February 16, 2017 What @LostKobrakai said. Just to expound on it. Your aim is to find pages [in this case 'coaches'] that use a particular category [in this case the children of 'Provinces']. As a by the way, it is also possible to do the inverse, i.e. find the 'categories' that a page uses. In that case, what you would be doing is just looping through Coach 1, etc, and outputting the category pages in their coach_provincie [i.e. the page reference field]; but I digress. Back to the question at hand. You do not need (can be dangerous, not user friendly, etc) code in your editor You do not need multiple templates for your provinces, i.e. Limburg, Drenthe, etc. Suggestion for your templates: Coaches:// template 'coaches' -Coach 1// template 'coach' -Coach 2// -ditto- etc. This is how my references tree looks like: Provinces:// template 'provinces' -Limburg// template 'province' -Drenthe// -ditto- -Utrecht// -ditto- Which coaches travel to this province? When viewing a particular province page, e.g. /provinces/limburg/ and want to find all coaches that are available for this province, all you need is to add Lostkobrakai's code above to the template file 'province.php' <div class="row"> <?php $coaches = $pages->find("coach_provincie=$page->title"); foreach ($coaches as $coach) { echo '<div class="col-md-6"><a href="'. $coach->url .'">'. $coach->title .'</a></div><div class="col-md-6">'. $coach->coach_locatie .'</div>'; } ?> </div> That code will return coaches that have 'Limburg' [the $page->title] in their page reference field (the one with the checkboxes - 'coach_provincie'). Which provinces does this coach travel to? On the other hand, if you want to know which provinces a coach travels to, e.g., Coach 1, (i.e. this URL /coaches/coach-1/, all you need to do is something like the below in the template file 'coach.php' foreach($page->coach_provincie as $destination) { echo $destination->title . '<br>'; } That's it . 3 Link to comment Share on other sites More sharing options...
tooth-paste Posted February 16, 2017 Author Share Posted February 16, 2017 Very helpful explanation. I will also use your approach mentioned in the second part, the provinces a coach travels to. Very user friendly, thanks! Link to comment Share on other sites More sharing options...
LostKobrakai Posted February 16, 2017 Share Posted February 16, 2017 Also if coach_provincie is a page field, where you select provincies directly, this selector works as well: "coach_provincie=$page" 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now