Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Can I ask some newbie advice please? Thanks...!

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
DSUK
Smarty n00b


Joined: 22 Aug 2003
Posts: 2

PostPosted: Fri Aug 22, 2003 11:18 am    Post subject: Can I ask some newbie advice please? Thanks...! Reply with quote

Hi, I'm trying to work out whether Smarty is going to be useful for me or not. This is a way oversimplified way of describing what I am looking for, but it gets the point across Smile

The website I am currently developing is heirachical:

Code:

Home
    What's New
    Links
    Blah...
Section 1
    Subsec 1
    Subsec 2
Section 2
Products
    Product Type 1
        Product 1.1
        Product 1.2
    Product Type 2
        Product 2.1
        Product 2.2
    Product Type 3
        Product 3.1
Section 4

etc. etc.


The overall look of the website will be based around 1 template (ie index.php) with variables in the url to select which include file is used for the content etc.

On SOME pages only, I want to apply other templates to the main template. For example, the PRODUCT descriptions (Product 1.1, Product 1.2, Product 3.1 etc...) I want to have the master template, a "product" template, and also another template for the *type* of product.

So, the page would have the main template, the product template (to show browsers they were in the product section), and then another template for the type of product (for eg, product type 1 is CDs, product type 2 is Software, product type 3 is Hardware and so on).

As I said, this is way oversimplified, and it's not just the "products" section that has to have different templates applied to it, but it serves as an example!

Is Smarty going to be helpful to me for doing this? Or can anyone suggest a better technology to use? I toyed briefly with the idea of using a CMS (Typo3, that sort of thing), but I have to design the site from the ground up, and cannot be limited to placing "blocks" on the page!! Laughing

Thanks in advance for any help.

Cheers!

Martin Hughes
Designer Sounds UK
Back to top
View user's profile Send private message
wvdploeg
Smarty Rookie


Joined: 05 Aug 2003
Posts: 19

PostPosted: Mon Sep 01, 2003 5:32 pm    Post subject: Re: Can I ask some newbie advice please? Thanks...! Reply with quote

Well, you say by yourself the way you describe it is over simplified, so maybe you did simplify it to much, but as you put it, I would not think of Smarty as a solution.
Back to top
View user's profile Send private message
CirTap
Smarty Pro


Joined: 04 Jun 2003
Posts: 106

PostPosted: Mon Sep 01, 2003 8:32 pm    Post subject: Reply with quote

sorry, but I totally disagree with you, wvdploeg.
Smarty is perfectly suited to solve this. It's just a matter of how you organize your templates and how you populate them with the required informations == template names, area, subpages etc.

If the master template (let's call it master.tpl) serves for the general look and feel of the site, you could let it {include file=$area_tpl} with $area_tpl being something like "products.tpl", "services.tpl" etc. assigned by the main script based on the URL.
The product and services template could again include "prod_type.tpl" etc.

Or you can use subdirectories to separate the different page types and keep the filename constant to indicate their purpose and avoid unpleasant filenames:
/templates/allover_meta.tpl
/templates/allover_header.tpl
/templates/allover_footer.tpl
/templates/index/master.tpl
/templates/products/master.tpl
/templates/products/hardware/content.tpl
/templates/products/software/content.tpl

So if you change /templates/products/master.tpl all subpages will change and the content(.tpl) therein. A clean structure and Smarty can automagically switch backand forth between whatever "design" you want for the different area.

[php:1:9f1b55f955]
$section = $_GET['section']; // e.g "products"
$smarty->assign("section_tpl", $section ."/hardware/master.tpl");
$smarty->assign("style", $section.".css");
[/php:1:9f1b55f955]
master.tpl wrote:

<html>
{include file="allover_meta.tpl"}
<link rel="StyleSheet" href="/css/{$style}" />
<body>
{include file="allover_header.tpl"}
{include file=$section_tpl}
{include file="allover_footer.tpl"}
</body>
</html>


This come close to "themeing" or "skinning" the site, and there was some recent discussion about how this could be done:click me

Simple coloschemes though should be done using a good and wellstructured <html> markup using stylesheets. The css filename would then be a simple variable like used in the above example code.

Happy evaluating, DSUK! Very Happy

CirTap
Back to top
View user's profile Send private message
CirTap
Smarty Pro


Joined: 04 Jun 2003
Posts: 106

PostPosted: Mon Sep 01, 2003 9:05 pm    Post subject: Reply with quote

I forgot to say: you should not make the template files decide what shuld be included when and why. This is a perfect job for your main PHP script so put a the logic to determine the required templates, filenames and paths in any PHP scipts. They may authenticate the user and switch to some "login.tpl" if neccessary.

At the end of this process, all the required (and resulting) variables are assigned to your $smarty instance. If your PHP script passes a path like "products/master.tpl" to *the* "index.tpl" it will load this one, if its called "services/master.tpl" it will be that.
In case the different sections differ totally from the main site's design, but share a common layout for their "own" various content pages (CD, software, hardware), you can still create a special designed "index_products.tpl" or alike.
Nobody prevents you from doing this.

Have fun,
CirTap
Back to top
View user's profile Send private message
wvdploeg
Smarty Rookie


Joined: 05 Aug 2003
Posts: 19

PostPosted: Tue Sep 02, 2003 5:14 pm    Post subject: Reply with quote

CirTap wrote:
sorry, but I totally disagree with you, wvdploeg.

Anyway, DSUK is helped by your answer (nice to see how it works... question has been ignored for over a week by everybody, one reaction 'smarty is not the tool' and see how DSUK is served Smile).

But as far as I understand DSUK his question his site is quite statical... personally I wouldn't think of PHP at all if a site has no dynamic content... (and believe me, in general I'm quite a PHP fanatic and for more complex solutions I LOVE smarty... but I'm also one of those people who does not take the car to go to the other site of the road Smile)

But anyway, if I misunderstood DSUK his question, CirTap gave a quite clear answer to 'how to solve it'.
Back to top
View user's profile Send private message
boots
Administrator


Joined: 16 Apr 2003
Posts: 5611
Location: Toronto, Canada

PostPosted: Tue Sep 02, 2003 5:26 pm    Post subject: Reply with quote

hi wvdploeg.

DSUK doesn't seem to be describing a static site to me. Regardless, a benefit of Smarty is that it can help you centralize your change control--which makes changing formats, adding items, etc, easy to do--especially if those changes are to be propgated to multiple pages. Further, that fact that Smarty compiles and even caches means that you get close to static speeds on sites that don't change often. Starting with Smarty also helps you grow your site when you suddenly want to extend your site.

I agree that Smarty is overkill for certain types of projects, but in DSUKs case, I can't see why Smarty couldn't be a good fit. I think your initial response to DSUK was a little thin, so as you say, its a good thing that ClrTap took up the challenge Smile

Cheers.
Back to top
View user's profile Send private message
CirTap
Smarty Pro


Joined: 04 Jun 2003
Posts: 106

PostPosted: Wed Sep 03, 2003 11:57 pm    Post subject: Reply with quote

wvdploeg wrote:
personally I wouldn't think of PHP at all if a site has no dynamic content...

that depends on how you define "dynamic" Smile
Just because some site is not "database driven" does not mean it's not "dynamic".
I helped a friend to add her stories and pictures to her personal homepage: the navigation and index pages (toc like) had to grow automatically when she uploaded a plain vanilla HTML file. As it was my initial job (as a friend) to maintain the said in the beginning, I just had not enough time to do all this manually for the rest of my life: reformatting the page, adding new links to a couple of pages, the "What's New" section and so forth. There's enough work to do, even if you just have a few dozend "static" pages that update regulary.
It's because they were static, I had to touch every single one ... SSI woudn't do as there are <link rel=section>, breadcrumb and other neat things.
I finally installed some scripts that collect her files, and put everything together.
The site's in a good, perfect shape although she has not the slightest idea of HTML. She writes content as hell -- and I go and have a beer Wink

And yes: I used Smarty for this, and it took me a rainy Saturday to restructure everything.

CirTap
Back to top
View user's profile Send private message
DSUK
Smarty n00b


Joined: 22 Aug 2003
Posts: 2

PostPosted: Mon Sep 08, 2003 12:36 pm    Post subject: Reply with quote

Thanks for the replies! (and thanks CirTap for the PM alerting me to the fact that there were replies!! Razz - I haven't checked the forum for a while!).

There are both static and dynamic pages on this site. I am leaning towards a database for it all. Even the “static” pages will need to be updated on a relatively regular basis. I am the sole person in charge of the website, so I’m not going to need any “web interface” to update – I will do it straight into the database (probably using the MySQL tools available on their website).

The TOC, News Articles, Links, Breadcrumb, Products Index/Categories, Solutions Index, What's New, Press Releases, Downloads (that will be a complex one!) blah blah blah... all have to grow automatically as new items are added. I have been looking on the hotscripts website and there are loads of things available on there, but mI don't want to have loads of "modular" things on the website, I would reather code it myself (I can reuse code for articles, what's new, press releases etc.) so I know it is customised EXACTLY how I want it to be, not setting a load of variables in config files for each item on the site Razz. The only things I will be using on a modular basis are OSCommerce for the Ecommerce side of things (store and hire library), PHPClassifieds for the ads page and PHPBB for the forums on the "community" subdomain.

I will post a link to the actual layout file for the website when I have uploaded it (after I get home from work!! Very Happy ) so you can see the exact layout of the site!

Thanks again for all the help!

Martin
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP