Share » Forums » Developer » Get a template output from a module

Get a template output from a module

Get a template output from a module

Wednesday 04 February 2009 9:15:54 am - 6 replies

Author Message

Ousmane KANTE

Saturday 07 February 2009 4:30:42 am

Hi,
Something like fetching the template would work:

$tpl = templateInit();

$node = eZcontentObjectTreeNode::fetch($your_node_id);
if($node)
$tpl->setvariable('node', $node);
$getdatafetch = $tpl->fetch('design:node/view/full.tpl');

Normally it will return the full view of your node (or it's override)

Consultant Ez Publish- Sapiens Consulting

Roberto Sacchi

Wednesday 11 February 2009 7:31:34 am

It works, but the problem is that I lost all css and image links in the output file.
The pagelayout.tpl is not included in the fetching (when I load node from ezpub, it's included)

How to do resolve it?

Roberto Sacchi

Wednesday 11 February 2009 7:58:58 am

I forget to ask you where have you found information about your code:

$tpl->setvariable('node', $node);

In Ez Docs and Classes I only have found:

eZTemplate::setVariable ( $ var,
$ val,
$ namespace = ""
)

that it's very generic.

When do you read that you can pass a node as variable?
Probably I miss some important documentation.....

Ousmane KANTE

Thursday 12 February 2009 7:11:03 am

You can use this "syntaxe" to add variable you want to use in your template.

as a node/view/[your_view].tpl, requires <i>$node</i> variable, you should be sur to have set it as tpl variable ...
if your template requires other variable(s), you can set it(them) as above...
For exemple, your css if you want to include them in node_view.

according to function definition and you can look at sample code in extensions such as ezdhtml (Online Editor).

Consultant Ez Publish- Sapiens Consulting

André R.

Thursday 12 February 2009 7:57:58 am

Or you can take a look in kernel\content\view.php, and see that it is a bit more complex then this.
But the code is reusable so a call like this will be enough to generate the whole $Result variable, and using the override system as well (the code above does not):

    $localVars = array( "cacheFileArray", "NodeID",   "Module", "tpl",
                        "LanguageCode",   "ViewMode", "Offset", "ini",
                        "cacheFileArray", "viewParameters",  "collectionAttributes",
                        "validation" );

    $cacheFileArray = array( 'cache_dir' => false, 'cache_path' => false );
    $args = compact( $localVars );
    $data = eZNodeviewfunctions::contentViewGenerate( false, $args ); // the false parameter will disable generation of the 'binarydata' entry
    return $data['content']; // Return the $Result array

You need to set all the variables in localVars though (see view.php for more info).

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Sebastiaan van der Vliet

Tuesday 24 May 2011 10:34:15 am

This code below also seems to work:

$moduleName = "Content";
  $Module = eZModule::findModule( $moduleName );
  $NodeID = [some node id];
  $ViewMode = "full";
  $Result = $Module->run( 'view', array( $ViewMode, $NodeID ),
                             array( 'ViewCache' => false, 'AttributeValidation' => array( 'processed' => true,
                                      'attributes' => false ),'CollectionAttributes' => false ) );
  print_r($Result);

Of course this only displays the contents of the full template. Does anybody know how to add the pagelayout.tpl code?

Certified eZ publish developer with over 9 years of eZ publish experience. Available for challenging eZ publish projects as a technical consultant, project manager, trouble shooter or strategic advisor.

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu