Jump to content

Change template file of a single page


Recommended Posts

I'm not 100% sure if I know what you're asking. If you want to display things differently, (a different view of the page content), you can turn on urlSegments for a particular template so that if the user goes to

mysite.com/projects/my-project/photos

where "photos" would be urlSegment1 of the "project" template, you could then output just the photos attached to that page.

So, on your "photo" template you could check the url:

if ($input->urlSegment1 == "photos" && count($page->images)) {
   include("./project_photos.inc");
} elseif ($input->urlSegment1) {
  throw new Wire404Exception();
} else {
 // do normal page stuff here
}

And in your "project_photos.inc" file:

echo "<h3>Photos for $page->title</h3>;

foreach ($page->images as $image) {
echo '<img src="$image->url" alt="$image->description">';
}

If this is what you want to do, go to "Urls" in your chosen template and turn on urlSegments.

Link to post
Share on other sites

For the developer is quite easy in this way :)

But for clients there should be an interface with a list of available visualizations (defined by developer) for the current template ....

I think that's a matter of opinion.

You could always create two templates which are allowed to be children of its parent.

Eg: project_brief and project_full

then let the client select which they want for each "project".

Or, you could provide the client with checkboxes to determine if they want to show/hide certain elements on each page.

Eg:

if ($page->show_breadcrumbs == 1) {
include("./breadcrumbs.inc");
}

Ultimately PW gives you ultimate control over what you (the developer/designer) want to do with the site.

You can go many ways about displaying the content. "views" using urlSegment, different templates or even giving the client choices by way of checkboxes.

There are probably many more too.

EDIT: Perhaps you can give us an example of what you are trying to achieve ADB and I'm sure there's some really easy ways to achieve it. I've yet to find something in PW that isn't easy to implement or that someone already hasn't provided code for.

  • Like 2
Link to post
Share on other sites

Ok, Thank you all for responses!

Anyway I was looking for something that not makes me write more code for change visualization.

A will make an Example with Plone, ( the CMS i want to supersede with PW ):

• Every Content Type have a customizable list of visualizations that correspond a template file.

for example:( Page with 3 columns, 2 columns and so on...)

• The user change, via interface, the visualization of that page.

The difference is that the CMS include the right file, without create another custom field or urlSegments that i must check with PHP.

I hope i have explain better!

Link to post
Share on other sites

ADB

It sounds exactly like you just want to use different templates.

Your page with three columns would be "three_columns.php"

Your page with two columns would be "two_columns.php"

Then in your text editor, create the different templates displaying it how you like.

So when adding a new page, the client can choose how they want to show the content.

I use it for full pages and pages with sidebar.

The client can choose which template they want to use for their new page.

You can also limit which templates can be used and where under the "Family" tab of Setup->Templates->Template_Name

Link to post
Share on other sites

You can also get even more clever, if you want to have some fun.

For instance, if you only want to have one layout, but change the color of all the H3 elements, you could create a select that gave alternatives like "blue headings," "red headings," "grey headings."

Or, more dramatic, you could ask if they wanted the side bar on the left or the right.

Then in your template php file, include the alternatives depending on what the select is - you can change classes, create layout alternative and so on, all on the same page and just call them with lots of if statements.

That then gives your clients some fine tuning while understanding what the result would be.

You can also do this by having lots of template alternatives - but if you are offering 4 or 5 things that they can alter, the permutations could get rather mind boggling!

Joss

Link to post
Share on other sites

Ehm... maybe the example i made was unlucky :(

I will try a different approach to explain my problem.

We made this site some months ago:

http://aou.udine.it

This site have only a few of Content Types (aka Templates in PW), and the most used Content Type is "Page".

The Page is used everywhere in the site in many different ways:

The News List http://aou.udine.it/notizie

A generic page http://aou.udine.it/azienda/chi-siamo

ecc...

So those views have very different HTML but the Content Type is the same.

But the key example is here:

http://aou.udine.it/innovazione/accreditamenti

schermata20121203alle20.png

Here there are all the subpages of the current page, if i click for example "Joint commission international" the content of those pages is displayed.

schermata20121203alle20.png

Well, this is a customized view because the default view is this : http://aou.udine.it/innovazione/accreditamenti/folder_listing

And the publisher decide where to use this view.

I know that i can create another Template in PW inheriting the fields of another, but the object is basically the same.

I know also that i can create a field that i check in the php file, but it is not well scalable and i mix real data with something regards of visualization.

Thanks all for patience!

Link to post
Share on other sites

I'm trying to simplify things somewhat but:

Do you want many different views of the same content?

-- If so, there really is nothing stopping you from using mysite.com/article/full and mysite.com/article/brief and then using urlSegments to output them. You'd just set some links to the different urls.

Link to post
Share on other sites

I'm trying to simplify things somewhat but:

Do you want many different views of the same content?

Yep!

-- If so, there really is nothing stopping you from using mysite.com/article/full and mysite.com/article/brief and then using urlSegments to output them. You'd just set some links to the different urls.

It's true (and sometimes i did it), but.... the urlSegment is write somewhere in the code. Is only a matter of flexibility :). I see that PW can do, more or less, everything!

Maybe at this point i will try to do a module for this!

Link to post
Share on other sites

I would do with options or checkboxes to the load different templates and views in the template php.

Or it is possible too change template file before rendering.

Theres so many ways and many things are possible. Looks like some sort of controller on temtplate of your multicontent page is best way togo.

Feel free and start build something and learn do thing different as your used to from another cms.

Link to post
Share on other sites

You can put templates within templates.

So, if the central bit of data is the same each time, but the content that goes around it needs to be different, you can include one inside another.

For instance, you can create a file called layout1.inc that has one version of the layout. Then include that in your template in the right position.

You can create several different layouts and decide which ones you want using options on your template. You can make the entire template up with 4 or 5 includes, all supplying different parts of the layout

For instance, I have a general page that looks like this:

<?php

$maincontent = "TB_mainbody.inc";
$secondcontainer = "TB_sidebar.inc";

/*
* Construction
*/

include("./includes/TB_head.inc");

include("./includes/main_layout.inc");

include("./includes/TB_foot.inc");
?>

The two variables at the top relate to includes that are in main_layout,.inc, in this case. So, this template calls three includes, and one of those (which has some very simple markup) calls two more that has all the main fields for the template. I can change the variables and I end up with something completely different.

It is probably a case of drawing it on a piece of paper, :)

Joss

Edit:

By the way, the reason I split the above into three files rather than have one full of variables, is that I like to be able to change the header and the footer of my template independently sometimes. It is not any better, but can make it a bit more reusable.

  • Like 1
Link to post
Share on other sites

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.

  • Similar Content

    • By rjgamer
      Hi,
      is there a hook after the current (active) page got created? Or which method got called in the Page class after the Constructor of the current page got initialized?
      Thanks.
       
    • By rjgamer
      Hi guys,
      the field "redirect_last" of type DateTime got not updated. The update on the field "redirect_counter" works and got saved.
      Does anybody know what I did wrong in my code?
      if ($input->urlSegment(1) === 'redirect') { $page->of(false); $page->redirect_last = time(); $page->redirect_counter += 1; if ($page->save('redirect_counter')) { $session->redirect($page->website_url, 302); } } Thanks.
    • By theoretic
      Hi there! And thanks for Processwire!
      I have an interesting task which i cannot fulfill as i want. Maybe someone could help me please?
      Let's imagine a simple page structure of this kind:
      Category 1
      + Item 1.1
      + Item 1.2
      Category 2
      + Item 2.1
      + Item 2.2
      My task is to attach some items to more than one category, at least to show some items on different frontend category pages. With PW, it's a piece of cake. I've just created a field called Items (of type Page Reference) and attrached it to Category template. Since i have lots of items inside each category i preferred to use Page Autocomplete input for my Items field. The pages available for autocomplete are restricted by a very simple selector:
      template=item
      It works like a charm. But later i decided to make this autocomplete even smarter and to exclude current category children items from it. I tried to update my selector this way...
      template=item,parent!=(page)
      ...and oops, this broke my selector. My autocomplete founds nothing. Sorry, i had to replace the square braces by () because of this forum limitations, i swear i'm using square brackets in real-life selector!
      What am i doing wrong? And is there any way to include current page info in autocomplete-related selectors? Thanks in advance!
       
    • By franciccio-ITALIANO
      Hi everyone.
      I've created 12 templates that are the same but each with an extra bit of html code. 
      The piece of code is as follows:
      <div> <div class="box-pf"> <i class="fa fa-map-pin fa-2x fa-red faa-pulse animated"></i> <a href=""> <span class="uk-text-middle"><i>Sonchus oleraceus</i> 'Grespino degli Orti'</span></b> </a> </div> </div> On the third line we read "fa-red."
      I created 12 similar templates.
      The first template has only one box with fa-red, the last template has 12 boxes with icons of 12 different colors.
      So. is there any way to have only 1 template and add, if I want and when I want, a small or big, same or different piece of html code?
       
    • By louisstephens
      So I ran into a very strange issue today. I have a template with a pagetable and I went to add an item to it, when I went to select an image (for an image field) the page instantly threw up an error
      "ProcessPageSearchLive: No search specified"
      The page's content also switched to the image attached. This all worked perfectly last week (local mamp box). Has anyone experienced this before, and how did you solve it?
       

×
×
  • Create New...