Jump to content

Recommended Posts

Posted

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?

Schermafbeelding 2017-02-15 om 08.34.54.pngSchermafbeelding 2017-02-15 om 08.35.43.png

Posted

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().

  • Like 1
Posted
3 hours ago, kongondo said:

Do you really need to generate menus in the text area? Why not in the pages' template files? :huh:

You mean to make a separate template for every single Tag? 

Posted
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?

Posted

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.

Schermafbeelding 2017-02-15 om 17.16.13.png 

Posted

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. 

  • Like 1
Posted

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>

 

Posted
<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?

  • Like 1
Posted

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.

  1. You do not need (can be dangerous, not user friendly, etc) code in your editor
  2. You do not need multiple templates for your provinces, i.e. Limburg, Drenthe, etc. 
  3. 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 :).

  • Like 3

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...