By Chill35 on
I am unable to find where in the themes folder $links and $terms are defined/styled.
In Drupal 4.7.4. links and categories terms in nodes are separated by a "|" character. They are not in Drupal 5, and I just want to add this character. For example :
.... implode(' | ', $links);
What file do I need to open ?
Comments
Ok I found it
It is theme.inc in /includes
BEFORE and AFTER
In /includes/theme.inc
BEFORE :
AFTER :
Why you must hack into the core?
With the theme_links of Drupal 5, we can apply the CSS style to the link, so why we must hack into the core to add the delimiter, why not just using CSS with .links class, add somethings like: border-left: 1px red solid; and you will have a links delimiter. Just some CSS knowledge and Keep It Simple :D
Good call. Yes, you even get
Good call.
Yes, you even get a class name for the first item and the last item in the list, so you can definately do as you say.
themeing
Even if that wasn't the case, even if you had to use some PHP, you can always avoid touching the core.
The prohibition to touch the core is one of the base tenants of the Drupal religion. Drupalers take this as a great offence ;-)
See the handbooks for info on themeing (or look for Nick Lewis' blog).
In a nutshell:
When some Drupal code wants to display some data, it does:
In our case, it does:
So you want to override the 'links' template. We obviously don't want to rewrite some code. How are we going to do that?
Create a file 'template.php' in your theme directory and in it create the function
phptemplate_links(). The theme() function first checks for this function before, as a last resort, it delegates to'theme_' . 'links'. Have a look at the source:http://api.drupal.org/api/HEAD/function/theme_get_function
(
'theme'. $functionis called last.)yeah, good info.
Mooffie, you deserve an award.
Actually I highly suspected that I could override that general function somewhere in my theme folder. For some reason, I felt reluctant to do so. I even visited the handbook on how to do this, but decided not do it. I think I take malicious pleasure out of editing the core stuff, it's sort of like stepping behind the altar at church. I want to make it mine. Of course if I don't take notes of all the changes I make, when I update for a reason or another, all my hard work will go to hell.
...
And that's fine for you. But encouraging others to do so increases the support burden for the rest of the community. Introduces bad practices to neophytes and causes them significant upgrade pains because they often do not know how to deal with the effects of what others have done.
-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide -|- Black Mountain
-Steven Peck
---------
Test site, always start with a test site.
Drupal Best Practices Guide
making drupal yours
Don't know about the altar thing, but I do know about "making a code mine." :-)
You make it yours by studying it. Drupal's core is small and easy to learn. And there's a bonus in learning Drupal's code: you get to know some really useful programming techniques. And... it's fun! That's the best part. So make yourself a cup of coffee and start enjoying yourself :-)
(Hmmm... but I doubt you can make a code yours by randomly poking at it here and there. On the contrary: the frustration might alienate you from the code.)
Mooffie
You explained so well what needed to be done, that I needed to look nowhere else for now and in 10 seconds it was done.
1. I opened an already existing template.php file in my [specific, i.e. Garland] theme folder.
2. I copied the code above -- my own code in there at the bottom.
3. I changed the delimiter to something else for testing, i.e. "*".
4. I renamed the name of the function to :
function phptemplate_links($links, $attributes = array('class' => 'links')) {5. I saved the template.php file, and opened my web site in the browser : just like a charm, all my links and terms were separated by stars...
Merry Christmas!
ps : now I will go undo the changes in theme.inc
And thank you for the warning ;)
Mooffie, I am not all done.
My overriding had an overlooked side-effect : my Primary Links are separated by "|" now.
How do you theme $links only for nodes ?
I don't think you must override the theme_links
I think with the default theme_links, you can do almost very things to styling your $links, to styling only for node links and terms link, in the node template (phptemplate.engine) you will found:
just edit to:
AND
change to:
then do anything you like with your css, no needs to override the theme_links just for add a little pipe character.
I don't want another class...
What if I wanted to change the HTML ?
Forget pipe lines, forget CSS, what if I wanted to change the HTML for $node->links and $node->terms ?
I have read all about themeing.
Without changing the phpTemplate.engine, there seems to be no way to do this specifically for node content. When you get to node.tpl.php, $links and $terms are already styled a certain way : they are delivered as an unorderded list of items. And if I change the phpTemplate.engine, I affect other themes that rely on it.
Other themes rely on CSS to add the "pipeline". I want to find ways to theme Garland and let it do what I want exactly. Maybe this is more of a question for the Theming forum, I apologize.
Thank you for all the incredibly useful info though. It's good to see how easy it is to add a class name, even if it relies on editing phptemplate.engine, which for some people here is considered "core".
more on themeing
First, a quick tip: if you want to find all places where the 'links' template is used, do
fgrep -R "theme('links" *in Drupal's root dir (I assume you're using some Unix variant).Second, we keep pretending that we can't do this using only CSS. That's fine.
Now, to your question.
First, you'd better make your 'links' function a bit more flexible by making the $delimiter a parameter:
Since the default delimiter is now an empty string, we're back to where we began: all links are displayed "normally", i.e. without any delimiter.
Now we want to print the delimiter only for nodes. There are at least two ways to do this without touching the core ('phptemplate.engine'):
1. The first method is simply to edit 'node.tpl.php'. The *.tpl.php files are not really considered core. Change the
print $linksstatement toprint theme('links', $node->links, ..., '*')and you're done.2. The second method, the "sophisticated" one, is to implement the
_phptemplate_variablesfunction in your template.php. The engine calls this function just before it parses the various *.tpl.php files in order to gives us a chance to modify (or add) any variables appearing there.Here's our implementation;
Feel free to edit the *.tpl.php files!
(You may prefer to make a copy of the theme.)
Yeah, yeah...
I don't know how I could have missed that... in my theme's 'node.tpl.php' file I not only have access to the themed $links but I still have access to $node->links -- as an array --, hence I can call theme('links', ....) on that array. However, I really want a separate function for theming links as just a paragraph containg anchor elements, one after the other. I don't want to mess with the themeing function that takes links and make an unordered list with them. So with your information (again, thank you, I don't know anyone here who explains things better than yourself... don't mean to flatter), I have defined a new theming function in my template.php file for my Garland theme :
With the extra parameter there, thank you!
So, in 'node.tpl.php', I use this specific themeing function : I am changing the
print $linksstatement toprint theme('links_in_node', $node->links, ..., '|').This way I make only two changes -- following from your first suggestion, the "unsophisticated" one.
- in .../Garland/template.php
- in .../Garland/node.tpl.php
This may seem not so important, it actually is not, but the whole theming aspect, my own learning of the phptemplate.engine and how themeing functions work is very important for me.
i am lost with this
i am a little lost as to what to do.
For context, every time i have created a template.php file it has broken my drupal install.
In this instance, all i want to achieve is for a comma delimiter between taxonomy terms (only taxonomy terms).
Given that i have failed with whatever i have tried (this, including using some of the code above - and other things) i am not really comfortable or confident in attempting to create a template file now.
i have yet to find something i can follow in the handbook (my programming days are in the past) - any help would be appreciated!
thanx
c.
[i was not a php programmer, though can follow what is going on to a degree]
avolve designs | ethical by design
Was looking for the same...
I was looking for the same after standing up a test 5.x site. The theme I use isn't available in 5.x, so I had to do my own converting. The links/taxonomy terms were sepearted by a "|" in 4.7 but not 5.x. I am no expert at this by any means, but I modified the style.css with the following:
ul {
list-style-type: disc;
}
ul.links li {
border-left: 1px solid #000;
}
ul.links li.first {
border-left: none;
}
Now my links and taxonomy terms are seperated by a bar.
Hope this helps.....
do you have
Good Day.
Do you have this online where I can see it? I am trying to configure my teaser layout to separate the cck taxonomy terms from the other links posted such as comment on post, etc.
I would appreciate any info.
Thank you,
Mark
Are you wanting....
mrgoltra,
Are you referring to my drupal site?
If so, sorry. It is an internal corporate site with no external access.
What have you tried so far?
mlcc2000
this code is great, ul
this code is great,
ul {
list-style-type: disc;
}
ul.links li {
border-left: 1px solid #000;
}
ul.links li.first {
border-left: none;
}
but how do you center your taxonomy terms?
Mine currently says:
padding-left: 1.5em;
I tried text-align: center; which did not work