Magento: obtener un bloque estático como html en un archivo phtml
Tengo un bloque estático llamado newest_product
(con contenido) y me gustaría mostrarlo en un .phtml
archivo como html.
He probado este código:
echo $this->getLayout()->createBlock('cms/block')->setBlockId('newest_product')->toHtml();
Pero esta nada se está mostrando.
¿Estoy usando el código equivocado?
8 answers
En el layout (app/design/frontend/your_theme/layout/default.xml):
<default>
<cms_page> <!-- need to be redefined for your needs -->
<reference name="content">
<block type="cms/block" name="cms_newest_product" as="cms_newest_product">
<action method="setBlockId"><block_id>newest_product</block_id></action>
</block>
</reference>
</cms_page>
</default>
En su plantilla phtml:
<?php echo $this->getChildHtml('newest_product'); ?>
No se olvide de la limpieza de caché.
Creo que ayuda.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2011-01-12 17:05:42
Si ha creado un bloque CMS llamado 'block_identifier' desde el panel de administración. A continuación, el siguiente será el código para llamarlos .phtml
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml();
?>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-11-27 06:15:46
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('my_static_block_name')->toHtml() ?>
Y utilice este enlace para más información http://www.justwebdevelopment.com/blog/how-to-call-static-block-in-magento /
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-04-27 07:03:28
Si desea cargar un cmsblock en su plantilla/blockfile/model, etc. Puedes hacer esto de la siguiente manera. Esto representará cualquier lugar de las variables en el cmsblock
$block = Mage::getModel('cms/block')
->setStoreId(Mage::app()->getStore()->getId())
->load('identifier');
$var = array('variable' => 'value', 'other_variable' => 'other value');
/* This will be {{var variable}} and {{var other_variable}} in your CMS block */
$filterModel = Mage::getModel('cms/template_filter');
$filterModel->setVariables($var);
echo $filterModel->filter($block->getContent());
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2012-10-11 09:09:42
Creo que esto funcionará para usted
$block = Mage::getModel('cms/block')->setStoreId(Mage::app()->getStore()->getId())->load('newest_product');
echo $block->getTitle();
echo $block->getContent();
Funciona, pero ahora las variables en el bloque CMS ya no están analizando: (
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-07 13:02:21
El siguiente código funcionará cuando llame a CMS-Static Block en Magento.
<?php echo
$this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml();
?>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-12-04 10:12:06
Esto debe funcionar como probado.
<?php
$filter = new Mage_Widget_Model_Template_Filter();
$_widget = $filter->filter('{{widget type="cms/widget_page_link" template="cms/widget/link/link_block.phtml" page_id="2"}}');
echo $_widget;
?>
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-11-17 06:41:36
Cuando crea un nuevo bloque CMS llamado block_identifier desde el panel de administración, puede usar el siguiente código para llamarlo desde su .archivo phtml:
<?php echo $this->getLayout()->createBlock('cms/block')->setBlockId('block_identifier')->toHtml();
?>
Luego borra la caché y vuelve a cargar tu navegador.
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2017-03-23 02:33:33