I created webform as block and I'm rendering in template like:
<?php print render($page['contact_us']); ?>
This working fine in .php, but in views not working.
I would say that you are rendering region that contains your block, not the block it self and you placed that block in "contact_us" region. But regions are available only in your page template.
Check out how to render block directly:
https://www.drupal.org/node/26502
So, it should be like:
$block = module_invoke('module_name', 'block_view', 'block_delta');
print render($block['content']);
And module name should be "webform". You can place this code directly in your view template, where you want your webform block rendered or in pre-precess function and then pass to your template as some variable and print it there.
Related
I use the Commerce Kickstart Distribution of Drupal 7. I want to have the searchbar assigned to a different region on the frontpage than on all other sites in my theme. I used the approach shown here: http://saw.tl/drupal/programmatically-manage-drupal-blocks.html
function mytheme_hook_block_info_alter(&$blocks, $theme, $code_blocks)
{
if(drupal_is_front_page()) {
$blocks['views]['-exp-display_products-page']['region'] = "branding";
}
}
This is the function in my template.php. I know that the search bar is created using the views module and is not a "default block".
The name shown in the Block menu for the search bar is Exposed form: display_products-page, the module name and machine name I choosed following this tutorial http://drupalchamp.org/node/166
However, it does not work at all. I do not get any errors or warnings, the block just stays in is default region when I load the front page.
You can use Context module to add blocks to different regions depending on some criteria:
https://www.drupal.org/project/context
Very powerful and easy to use module so I'm advising it.
And if you prefer doing it form code you could grab block's content and print it from template directly, depending on detected page. Something like:
$block = module_invoke('views', 'block_view', 'block_machine_name');
print render($block);
Of course you would execute it conditionally...
I'm using [insert_php] plugin in Wordpress and I have inserted php function in it.If I set the block with the function before the the masonry grid it doesn't load.
If I move the block with the function after the grid it works well.
In console log is appearing an alert:
Syntax error, unrecognized expression: {'status':'Nothing found'}
How can I sole that?
Grid before php block
Block php before the grid
What you need to do is create a page template. This page template can be used to create PHP for your page to load, and you can even use
<?php echo do_shortcode('[shortcode]'); ?>
To create a template just copy your page.php into a new file called tpl_test.php.
Then make sure to have this in the very first line:
`<?php
/*
Template Name: Test Template
*/
?>`
Then, a small window will show up on the back-end of WordPress when you edit the page. In the right hand column you need to select the page template for the page you just created, and update the page. then, any code you put in the custom Page Template will display correctly on your WordPress site. Also, make sure <?php the_content() ?> is below your grid you are trying to output.
I have a short code
{{block type="ibtheme/product_list_featured" category_id="51" random_products="" template="catalog/product/list/featured.phtml"}}
which is working fine in editor from backend. How can U call the same short-code from a PHTML page ?
When I put the same code, it is printing a simple text.
phtml is php code, not cms html passed through a filter to catch the short codes (macros) and expand them out.
The contents between "{{" and "}}" must interpreted by a template engine and is only valid inside emails, CMS pages/blocks and the wysiwyg editors in the backend.
You put their equivalent into layout and call them as in the following ->
Magento Shortcode CMS block not working on product pages
In Magento CMS or Static block, if you want to add PHP code then you can just call any custom .phtml file by using following code. Like here I am including my_custom.phtml.
{{block type="core/template" name="myCustom" template="cms/my_custom.phtml"}}
This is equivalent to following layout tag:
<block type="core/template" name="myCustom" template="cms/my_custom.phtml">
Hope you find it useful.
The above answers are both incorrect if I'm reading that you would like to use shortcodes in phtml pages. I use these frequently, since we have a tremendous amount of content, and breaking them down in to phtml blocks is the easiest way for us to keep our content fresh.
Anyhow, here's the correct way to use call blocks in phtml:
<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('cms/my_custom.phtml')->toHtml(); ?>
For Example, to use the block in your original answer would be
<?php echo $this->getLayout()->createBlock('ibtheme/product_list_featured')->setTemplate('catalog/product/list/featured.phtml')->toHtml(); ?>
I think this is what you're actually looking for. The code is in the CMS module in the Magento code.
<?php
// Load the cms helper
$helper = Mage::helper('cms');
// get the cms static block processor
$processor = $helper->getBlockTemplateProcessor();
// run the content with the shortcode through the filter
// in this case $item->getAnswer() contains a shortcode
$html = $processor->filter($item->getAnswer());
// print it to the page
echo $html;
?>
Remember anything is possible, just dig deeper. If in doubt, copy the Magento core code.
In Drupal 7
created a block view (called *super_gallery*) of grid format
added a template specialization views-view-grid--super-gallery--block.tpl.php
cleared theme registry
cleared all caches
Using preview in view editor I can see output modified by the template. GOOD
Using <?php print views_embed_view("super_gallery", "default", $gallery_arguments); ?>
inside another template to show *super_gallery* view, it shows output without changes. BAD
How can I use templates with views_embed_view?
EDIT 1
Tried also with:
$view = views_get_view("super_gallery");
print $view->preview("default", $gallery_arguments);
and
$view = views_get_view("super_gallery");
print $view->execute_display("default", $gallery_arguments);
Nothing changed
Have you tried?
print views_embed_view("super_gallery", "block", $gallery_arguments);
Have a look at this module
http://drupal.org/project/embed_views
OR Have a look at the following comment
http://drupal.org/node/1138866#comment-4845070
this is in my theme.info file of my Drupal theme:
regions[conf_modules] = Configurator: modules
I'm using multiple templates for different node types. In one of them I'd like this region/block to show up. So I've put this in node--configurator.tpl.php:
<?php print render($page['conf_modules']); ?>
In the Drupal administration panel I have assigned a views block to the region, but on the node--configurator.tpl.php pages, the views block is not shown. Am I using render() properly? What's going wrong here? Thanks in advance!
In node templates, $page is simply a status variable that is:
True if the node is being displayed by itself as a page.
However, you can add regions to the page for specific content types through your page.tpl.php if you like. Something like below should work if placed in page.tpl.php:
<?php
if ($node->type == 'CONTENT_TYPE') {
print render($page['conf_modules']);
}
?>