I'm very new to drupal, and I'm studying it.
I'm trying to port bluemarine from phptemplate to smarty engine. Unfortunately I can't see any smarty theme ready for drupal 6 so I have no example to refer to and the updated documentation seems to be the README.txt file included in the smarty-engine package.

I assume that throught smarty.engine all the common theme functions for drupal are ported to the smarty environment.

Right now the porting it's pretty good and easy. Infact all the work in the .tpl file seems to be to rewrite in a proper smarty-way the output of variables.

But (there is always a "but" :-D) a problem comes out with primary and secondary links
This code prints the primary links in bluemarine

<?php if (isset($primary_links)) { ?
        <?php print theme('links', $primary_links, array('class' => 'links', 'id' => 'navlist')) ?>
<?php } ?>

I did this (a stupid way I know)

{php} if (isset($primary_links)) 
	print theme('links', $primary_links, array('class' => 'links', 'id' => 'navlist'));
{/php}

I think it should work but nothing happens. Why?

Another question related:
I saw in the smarty.engine file the function

function smarty_theme($existing, $type, $theme, $path)

I found the same function in phptemplate.engine

I think that this function should overwrite the hook_theme function. Is it true?
I think that this fun

Thanks in advance to anyone would help me
--
enjoy
Dam

Comments

dam’s picture

this code of course works.

     <!-- primary links	 -->
     <ul class="links" id="navlist">
		{foreach name=outer item=link from=$primary_links}
		    <li ><a href="{$link.href}">{$link.title}</a></li>
		{/foreach}
	</ul>    

But I don't think it's the better way.

I'm curious to know if I can access the theme link function in the same way it happens for the phptemplate engine.

dam’s picture

this is getting me mad.

I did another test:
$primary_links is a 3 depth array

I added these rows in page.tpl

{php}theme('links',$primary_links, array('class' => 'links', 'id' => 'navlist')){/php}

and this in theme.inc

function theme_links($links, $attributes = array('class' => 'links')) {
  echo "num links: ".count($links);
  echo '<pre>';
  print_r($links);
  echo '</pre>';
[cut]

the result is:

num links: 0
array();  // empty

but using this in the same page.tpl

     <!-- primary links -->
     {if isset($primary_links) and $primary_links!=""} 
     <ul class="links" id="navlist">
		{foreach name=outer item=link from=$primary_links}
		    <li ><a href="?q={$link.href}">{$link.title}</a></li>
		{/foreach}
	</ul>
     {/if}

I can see the primary_links properly (4 elements)

It seems that the variable primary_links get empty somewhere .. can't really understand this

dam’s picture

I read this row in the README.txt

The way Smarty plugins/'wrapper' functions work has changed. Create a function
mytheme__register_smarty_functions in your theme's template.php which returns an array
like the array $plugins in function &_smarty_get_object

Probably it's what I'm searching for but it's really too poor to be understood. Now I really need a help. I have no more resources :-(

dam’s picture

also if I seem completely crazy due to the fact that I'm speaking alone ...
I read this in theme.inc

" * In order to create theme-specific implementations of these hooks,
* themes can implement their own version of theme hooks, either as functions
* or templates. These implementations will be used instead of the default
* implementation. If using a pure .theme without an engine, the .theme is
* required to implement its own version of hook_theme() to tell Drupal what
* it is implementing; themes utilizing an engine will have their well-named
* theming functions automatically registered for them. While this can vary
* based upon the theme engine, the standard set by phptemplate is that theme
* functions should be named either phptemplate_HOOK or THEMENAME_HOOK. For
* example, for Drupal's default theme (Garland) to implement the 'table' hook,
* the phptemplate.engine would find phptemplate_table() or garland_table().
* The ENGINE_HOOK() syntax is preferred, as this can be used by sub-themes
* (which are themes that share code but use different stylesheets)."

This doesn't happen in smarty!
I tried overriding in template.php .. nothing ... a function smarty_links would not be read
Even smarty_theme inside smarty.engine is never read

if I put an echo inside smarty_theme but is never output. this means is never parsed. why? it should be done automatically by drupal when a template is using smarty engine. right?

djnz’s picture

Sorry, this is not well documented. I have tried to take over the Smarty documentation but do not have access yet :(

To use Drupal's links which are simply an unordered list formatted with CSS, use the following functions in Smarty:
{theme_links links=$primary_links id='navlist'}
{theme_links links=$secondary_links id='subnavlist'}

A more smarty-like way of doing this would be to just get an array of links and do the HTML generation in the template: I have this working on my server but it is not in CVS (yet).

lvthunder’s picture

That's what I have in my theme and it works in Dupal 5, but in Drupal 6 I get this error

user error: Smarty error: [in themes/greypop_smarty/page.tpl line 31]: syntax error: unrecognized tag 'theme_links' (Smarty_Compiler.class.php, line 590) in C:\Users\Stephen\workspace\lvthunder\webroot\themes\engines\smarty\libs\smarty.class.php on line 1092.

user error: Smarty error: [in themes/greypop_smarty/page.tpl line 34]: syntax error: unrecognized tag 'theme_links' (Smarty_Compiler.class.php, line 590) in C:\Users\Stephen\workspace\lvthunder\webroot\themes\engines\smarty\libs\smarty.class.php on line 1092.

Also my sidebar isn't showing up in Drupal 6. This is the code I'm using.

{if $sidebar_left ne ""}
<td class="sidebar" id="sidebar-left">
{$sidebar_left}
</td>
{/if}

Any ideas? Also are there any Drupal 6 themes that use smarty?

barretr’s picture

Try $left, instead of $sidebar_left. Unfortunately, there are no Smarty themes available for Drupal 6.x, yet...

lvthunder’s picture

That worked. Thanks barretr. Now all I have to do is figure out the primary links problem.

lvthunder’s picture

I have no idea if this is the proper way to do this or not but I think I got it working. I put an empty function.theme_links.php file in the plugins folder of the smarty theme engine then added the following code to smarty.engine at line 267

/**
 * Smarty theme_links function plugin
 * Return themed HTML for links
 */
function smarty_function_theme_links($params, &$smarty) {
  if ( isset($params['links']) ) {
    if ( isset($params['id']) ) {
      $attribs = array('class' =>'links', 'id' => $params['id']);
    } else {
      $attribs = array('class' =>'links');
    }
    return theme('links', $params['links'], $attribs);
  } else {
    return '';
  }
}
Whiting’s picture

Hi there,

I'm just about to get started on a drupal 6 site for which I'd like to use smarty. I have spent a bit of time trying to track down a template so I don't have to start from scratch.

Would appreciate knowing where you are up to with this and if there's any chance I could have access to the code?

Cheers
Matt

lvthunder’s picture

Here's mine. I doubt it's a complete theme, but it works for me
http://www.lvthunder.com/greypop_smarty.zip