Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By randomyao22 on
Usually I use node-20.tpl.php to build a template file for node which nid is 20.
But if I build a lot of template files.
It looks like this in my theme fold:
node-20.tpl.php
node-32.tpl.php
node-43.tpl.php
node-54.tpl.php
node-66.tpl.php
node-68.tpl.php
...
It is hard to know which page they are for.
Is there a way to name the template file in this format:
node--{node slug}.tpl.php
e.g.
node--about.tpl.php
node--contact.tpl.php
Who knows that?
Comments
_
You can add template suggestions for just about anything you can think up. For one approach see https://groups.drupal.org/node/130944.
Hi WorldFallz,
It looks like a good solution for Drupal 7 but I'm working on Drupal 6.
I still need to look for another way.
Thanks anyway!
=-=
tagging your thread with the version of drupal in use aids.
you can create custom suggestons in D6 as well see: https://drupal.org/node/223440#custom-suggestions
Thanks VM, That document is
Thanks VM,
That document is really helpful. Now I can create a page-about.tpl.php by the following code:
But I'd like do the same thing using node-about.tpl.php
Then I change the code to:
But it not works. Do you know where is the problem?
I tend to argue if you have
I tend to argue if you have that many node specific templates you are probably on the wrong track. Why not just use html in the node body to format as needed?
There's some contents liking
There's some contents liking customised forms that required PHP code which I can not write in rich editor.
Best practices would say to
Best practices would say to create a module that uses the Drupal API.
But you still need to call
But you still need to call those PHP functions in the template. Maybe there is another way?
Templates should not be
Templates should not be defining PHP functions, there are indented for laying out what ever data the template is for. I really sound like you need to look at the Drupal form API.
I indeed checked the Form
I indeed checked the Form API.
I'm not tend to define functions in node template, but I need to use functions in the template. Even form API, you can't use html to add these API forms into a specific page. How can I do that?
In general one would create a
In general one would create a module that uses hook_menu() to define the pages for each of the forms. Alternatively you could define blocks for each form and use the block admin page to add them to existing pages.
Thanks for explaining on it.
Thanks for explaining on it. That sounds good.
I will take time to study how to using hook_menu() create pages.
BTW, could you help me to see where is the above code's problem?
Does your theme have a
Does your theme have a node.tpl.php file? It is required for the alternative node.tpl.php files to work.
Yes. I have node.tp.php. Also
Yes. I have node.tp.php. Also node-20.tpl.php works well.
I've worked on hook_menu(),
I've worked on hook_menu(), use it to create pages, and use hook_theme() to template the page. That is fantastic!
Thank you guys!