1

I am new to drupal, I read some introductory tutorial.

I notice there is some theme() function in template files.

Like this:

<?php print theme('uc_price',array('price'=>$price)); ?>

It will generate some html source code:

<span class="uc-price" data-thmr="thmr_45">$59.85</span>

Is it theme() function is only to generate the html source? If this is the case, why I need use theme() function? I Think just only write html source manually.

I use Zen base-theme, Does theme() is one of zen's native function?

Please tell me the real usage of "theme()".

0

Your understanding about theme is right. It is for wrapping data with html elements. Advantage is that you can seperate view part and logic part. There are also default theme which you can use out of box

  • theme() seems only generate <span>, and what's meaning of data-thmr="thmr_45"? – TangMonk Feb 1 '14 at 7:38
  • first attribute "uc_price" is the name of the theme. There are lots of other themes like 'image_style', etc. To call image_style theme you use theme('image_style',array(...)) You can create your own theme as well. and data-thmr="thmr_45" i dont know what html attribute that is. That is not very important thing. – Nabil Feb 1 '14 at 7:52
  • Thanks for your reply, This is my understand: theme() is a drupal native function, and some modules and base-theme will implement theme() function, and add more out of box method. right? – TangMonk Feb 1 '14 at 8:00
  • You are right. But our discussion here alone wont give much insight to the concept. Continue your effort. my wishes – Nabil Feb 1 '14 at 8:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.