sebibu Posted 9 hours ago Share Posted 9 hours ago I really love LATTE (Template Engine by Nette) but here and there I still have problems with the syntax. I'm using RockPageBuilder by @bernhard and try to output the html for this module: https://processwire.com/modules/fieldtype-leaflet-map-marker/ In PHP this would be: <?php echo $map->render($page, 'YOUR MARKER FIELD'); ?> And in LATTE? 😆 I tried this variants and more: {$map->render($page, 'map')} {$map->render($page, 'block->map')} {$map->render($page, $block->map)} Getting: Call to a member function render() on null in block #1158 (rockpagebuilderblock-map) Maybe this topic can be a collection point for smaller Latte syntax questions. Link to comment Share on other sites More sharing options...
bernhard Posted 9 hours ago Share Posted 9 hours ago This <?php echo $map->render($page, 'YOUR MARKER FIELD'); ?> would be this {$map->render($page, 'YOUR MARKER FIELD')} Your error message means, that $map is NULL. That means $map is not available in your latte file for whatever reason. That means you are not struggling with latte syntax, you are struggling with PHP 😉 😛 You can easily debug this via TracyDebugger: {bd($map)} {bd($page)} To help you with your specific problem I'd need more info in where you are trying to use this markup... 1 Link to comment Share on other sites More sharing options...
MrSnoozles Posted 9 hours ago Share Posted 9 hours ago (edited) It looks like you need to make $map available in your Latte file first. Then, as Bernhad has said, you could write in your Latte file {$map->render($page, 'YOUR MARKER FIELD')} With https://processwire.com/modules/template-engine-latte/ you would write something like the following in your PHP template file (or ready.php): $view->set('map', $map); It might vary depending on which modules you use exactly in your project. Edited 9 hours ago by MrSnoozles Link to comment Share on other sites More sharing options...
bernhard Posted 9 hours ago Share Posted 9 hours ago 6 hours ago, MrSnoozles said: $views->set('map', $map); RockFrontend / Latte doesn't provide this syntax as far as I know. What are you referring to? 6 hours ago, sebibu said: https://processwire.com/modules/fieldtype-leaflet-map-marker/ Ah sorry, now I see $map should be a map marker object. The docs there state this: <?php $map = wire('modules')->get('MarkupLeafletMap'); ?> Which you could do in latte like this: {var $map = $modules->get('MarkupLeafletMap')} Link to comment Share on other sites More sharing options...
MrSnoozles Posted 9 hours ago Share Posted 9 hours ago 1 minute ago, bernhard said: What are you referring to? Updated the post to be clear it's an example and varies depending on which modules are used. 1 Link to comment Share on other sites More sharing options...
sebibu Posted 2 hours ago Author Share Posted 2 hours ago Thanks for your help! Trying.. {var $map = wire('modules')->get('MarkupLeafletMap')} {$map->render($page, 'map')} ..in RockPageBuilder block LATTE-file I get: Call to undefined function wire() in block Trying.. {var $map = $this->$wire('modules')->get('MarkupLeafletMap')} {$map->render($page, 'map')} .. I get: Method name must be a string in block Now I'm confused. 😆 What I'm doing wrong? Link to comment Share on other sites More sharing options...
bernhard Posted 2 hours ago Share Posted 2 hours ago Sorry, wire() is not available in a latte file, because wire() is actually \ProcessWire\wire with the namespace. In PHP files where you have "namespace ProcessWire" at the top just adding wire() will work. In latte it is a different story, because the latte file has no namespace and it will be compiled. Therefore "wire()" is not available. But all ProcessWire API variables are, so please just use $wire instead of wire(). Pro-Tip: From any API variable you can access the wire object via ->wire, so this would also work: $block->wire->... or $config->wire->... etc.; So in hooks you might see $event->wire->... and that's the reason for this. PS: $block is not an API variable but is available in RockPageBuilder blocks! And as it is also extending "wire" it will also have its methods. Edit: I've just updated the example above and realised that it was using wire('modules') syntax that I'm never using. In that case you need to use $wire->modules->... or simply use $modules->... as $modules is also an API variable and therefore directly available. Link to comment Share on other sites More sharing options...
Recommended Posts