Gossamer Forum
Home : Products : Gossamer Links : Discussions :

help needed

Quote Reply
help needed
Hi,



I want to be able to give each of my categories its own customized detailed.html

I am working in the sitehtml.pm file under sub site_html_detailed section Heres what I have so far and it builds with out any errors:



# Set the template set to use.

my $opts = { dynamic => 1 };



# Find the proper template.

my $viewtemplate;



if ($rec->{Category_Template} and ($rec->{Category_Template} =~ /^jobs/)) {

$viewtemplate = "detailedjobs.html";

}

else { $viewtemplate = "detailed.html";

}

my $output = Links::user_page ($viewtemplate, $rec, $opts);

return $output;





I want it to build from the main default folder templates/default

And I'd just add the templates there like detailedjobs.html



Now I thought that's how you point it to the jobs category but its not working



Could anyone tell me how you point it to the jobs category ???



Thanks

Quote Reply
Re: [incik] help needed In reply to
Why not just edit detailed.html to use something like;

<%if Title eq 'Jobs'%>
<%include job_detailed.html%>
<%elsif Title eq 'Computers'%>
<%include computers_detailed.html%>
<%else%>
<%include default_detailed.html%>
<$endif%>

Then you would be able to create new template pages, according to the design of your site/category, and add as many of the 'elsifs' as you want. Much easier than messing with the code IMO Wink

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [AndyNewby] help needed In reply to
The problem is that the <%include%> tag can't seem to take a variable for the include file.

You have to have a very large cascade.

If you alter the code, then you can use a variable replacement, that depends on the category name, rather than hard-coding in 20,000 categories....


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] help needed In reply to
So your saying using a <%Description%> tag in job_detailed.html would not work? It works ok for me with different link styles (3 link templates, each for the appropriate style, and then using Includes in link.html).

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [AndyNewby] help needed In reply to
I haven't been able to get the construct:

If <%category_name%> is the name of the current category, in whatever format you want to use to keep track of them,

I have not been able to get:

<%include category_name%>

to work, using any of the potential means in the Template help docs.

If it were possible to set Template_Name via a global call, then load:

<%include Template_Name%>

you could save an _awesome_ amount of hard coding of if statements.

Even with the $ modifier, I can't make it work.

The only way to make it work, is to set up a global or external function, that uses perl to figure out the template you want, load it, parse it, and return the parsed HTML as a simple <%some_tag%> in the file.

I brought this up a couple of months ago, but don't remmeber Alex commenting on it.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] help needed In reply to
Hi,

Well, the global method is pretty easy.

<%include Template_Name%>

translates to:

global =>
sub {
my $tags = shift;
return GT::Template->parse($tags->{Template_Name}, $tags);
}

I can see the need for variables in includes though, I'll see how hard it would be.

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Alex] help needed In reply to
I'm a little confused can you give me step by step instructions on what to do ?

Thanks
Quote Reply
Re: [incik] help needed In reply to
How many categories do you want to change, and how will you do it.

What alex says, is:

Doing:

<%include Template_Name%>


Where Template_Name is the name of a global, that does:

Template_Name =>
sub {
my $tags = shift;
## figure out what template to parse
## and stuff it into $tags->{Template_Name}
return GT::Template->parse($tags->{Template_Name}, $tags);
}

(I admit, I'm a bit confused with the above, so I might not have it fully right.)

The trick, is to have some sort of naming convention for your templates. If you store the template name in the Category record for that category, you could check to see if that field was defined, and if it was, use that template, otherwise, use the default template.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] help needed In reply to
I think I understand

Would this be placed into the template.pm file ?

and if so should I just place it in the end or begining of the file ?

Thanks
Quote Reply
Re: [incik] help needed In reply to
No....

You'd make this a global in the globals.txt file.

You'd insert the tag into the template you are serving.

You won't have to edit any .pm files, and this should survive upgrades between versions.

You'd need to come up with a way to name the templates, I would suggest category_ID_detailed.html and category_ID_category.html this will make developing multiple templates easier.

You can do the same for add.html and including in the form.txt file, different for each category, if it has to be.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] help needed In reply to
I kinda got confused so this is what I tried

I put this in the detailed.html file

<%if Title eq 'jobs'%>
<%include detailedjobs.html%>

<%else%>
<%include detailed.html%>
<$endif%>


Then in the globals.txt file I put

global =>
sub {
my $tags = shift;
return GT::Template->parse($tags->{Template_Name}, $tags);
}



and I also tried replacing Template_Name with detailedjobs.html but it still didnt work

anything else i should try ?
Quote Reply
Re: [incik] help needed In reply to
Yes, I think what Alex meant in detail was something like the following.

1) Define a global

Code:
Category_Detailed =>
sub {
my $tags = shift;
if ($tags->{Category_Template}) {
$tags->{Category_Detailed_Template} = "detailed_$tags->{Category_Name}.html";
}
else {
$tags->{Category_Detailed_Template} = 'detailed_default.html';
}
return GT::Template->parse($tags->{Category_Detailed_Template}, $tags);
}
2) Put your templates called "category_XXX_detailed.html" in your templates directory, where XXX is the Category_Name

3) In detailed.html, simply put <%CategoryDetailed%>.

This produces a different detailed template for every category that has "Category_Template" defined, if it is not defined it uses "detailed_default.html" (which you also have to put in your template dir, btw)

I haven't tested this code, but it should work.

Ivan
-----
Iyengar Yoga Resources / GT Plugins
Quote Reply
Re: [yogi] help needed In reply to
I tried what you wrote to do
but it didnt work also

Thanks for trying
Quote Reply
Re: [incik] help needed In reply to
Actually, I just saw that there is a mistake in step three: it should be <%Category_Detailed%>, and not <%CategoryDetailed%>.

Apart from that, I don't know.

Ivan
-----
Iyengar Yoga Resources / GT Plugins