Jump to content

Change template file of a single page


Alessio Dal Bianco
 Share

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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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 comment
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
 Share

×
×
  • Create New...