We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Can you add "Placeholder" pluin like Zend Framework in View?

In layout view template:

<?=$this->placeholder("footerjs");?>

In action view template:

<?php $this->placeholder("footerjs")->captureStart();?>

......some complex js script or css tag.

<?php $this->placeholder("footerjs")->captureEnd();?>

can Phalcon add this new feature?



1.9k

Maybe you can check out Phalcon Assets to do that job



3.8k

@ntesic

I had read the Phalcon Assets,But it's can't solve the problem, or can you give me some examples? thank you.



3.8k

thank you,

I known, I means can you add the placeholder feature at next release?

pwtitle, I think I was able to recreate the missing functionality by using output buffering and assigning the results to a view variable as follows:

In the action's view:

<!-- // -------------------------------------------------------------------------------- // --> <?php ob_start(); ?> <script type="text/javascript"> $(document).ready(function () { ... }); </script> <?php $this->view->setVar('jscript', ob_get_clean()); ?> <!-- // -------------------------------------------------------------------------------- // -->

Then, inside the modules "template" view, use that variables as follows:

<!-- Custom Page JavaScript --> <?php if (isset($jscript) && $jscript): ?> <?= $jscript; ?> <?php endif; ?>

This will scoop up the custom JS, exclude it from the action's view, assign it to a view variable, and that variable can be used in the main template to render it in the correct position.

-- Dante