When using this syntax to loop on a 'component' EJS is complaining that task is not an object but if replaced with task._id it's fine.
Any ideas please?
<? tasks.forEach( function( task ){ ?>
<?- include('_task'); ?>
<? }) ?>
If you're asking how to pass task to your include then it'd be something like this:
<? tasks.forEach(function(task) { ?>
<?- include('_task', {task: task}) ?>
<? }) ?>
Top-level data is automatically included but local variables need to be passed explicitly. See https://github.com/mde/ejs#includes
Related
I'm trying to check whether product has custom options or not in code (my code runs sales_order_place_after event).
I have try below code but it does not returning anything.
$product->hasCustomOptions()
and
$product->hasOptions()
Please let me know what I'm missing.
I've encountered this error more times than I care to count. Either $_product->hasOptions() or $_product->hasCustomOptions() always returns false. I still don't know why this error occurs.
Anyway, you can get the same result by doing the following. For configurable products:
<?php if ( $_product->getData('has_options') ): ?>
<!-- do something -->
<?php endif; ?>
And to get the same result for simple products with custom options:
<?php if ( $_product->getData('has_options') && ($_product->getTypeID() == 'simple') ): ?>
<!-- do something -->
<?php endif; ?>
I hope that helps a future adventurer!
EDIT
The solution above does not work in loops when the flat category data option is enabled in Magento, and we don't want to reload the product inside the foreach loop!!
Instead, we can check for custom options using the following singleton inside the loop:
$opts = Mage::getSingleton('catalog/product_option')->getProductOptionCollection($_product);
$optsSize = $opts->getSize();
if ( $optsSize ) {
... // go go go
}
use the method $product->getHasOptions()
I have a page template where I run a WP_Query
$temp = $wp_query;
$wp_query= null;
$wp_query = new WP_Query();
$wp_query->query('post_type=post&posts_per_page=4'.'&paged='.$paged);
while ($wp_query->have_posts()) : $wp_query->the_post();
The issue I'm facing is that if you go to the site /page/100 it will show the template and it's not going to a 404 when It should.
My blog page under reading settings is another page and this is a custom template I'm doing.
I have read this post https://wordpress.stackexchange.com/questions/46116/non-existing-blog-pages-are-not-redirected-to-404 and tried all the functions and none of them work.
I also spent 3 hours searching on google without being able to find a workaround.
You are creating a new WP Query. So I think you have to reset the wp_postdata.
WP Codex offers sample code. You could try something like
$wp_query = new WP_Query();
$wp_query->query('post_type=post&posts_per_page=4'.'&paged='.$paged);
if( ($wp_query->have_posts() ) :
while ($wp_query->have_posts()) : $wp_query->the_post();
// Do here something with the post
endwhile;
wp_reset_postdata(); // At the end reset your query
endif;
While using WP_Query for displaying posts list you need to check by yourself if they are any posts for current page. Below is example code from Wordpress docs
<?php if ( have_posts() ) : ?>
<!-- Add the pagination functions here. -->
<!-- Start of the main loop. -->
<?php while ( have_posts() ) : the_post(); ?>
<!-- the rest of your theme's main loop -->
<?php endwhile; ?>
<!-- End of the main loop -->
<!-- Add the pagination functions here. -->
<div class="nav-previous alignleft"><?php next_posts_link( 'Older posts' ); ?></div>
<div class="nav-next alignright"><?php previous_posts_link( 'Newer posts' ); ?></div>
<?php else : ?>
<p><?php _e('Sorry, no posts matched your criteria.'); ?></p>
<?php endif; ?>
Replace " _e('Sorry, no posts matched your criteria.'); "
with own error or function displaying 404 error.
Edit: Above code is of course example for Main Loop. In your particular case you need to call $wp_query->have_posts() and make sure it not evaluates to false. If it does display 404 error.
for example:
if(!$wp_query->have_posts()) {
echo "404";
}
Or if you want server respond with HTTP code 404 instead of 200 then you should try something like this:
if(!$wp_query->have_posts()) {
status_header(404);
nocache_headers();
include( get_404_template() );
exit;
}
How to disable particular layout(example:menus.phtml) for particular pages in controller in ZF2?? In the below example menus.phtml should be disable for specific pages. Remaining pages must contain menus.phtml like header and footer.
<div>
header.phtml
</div>
<div>
menus.phtml
</div>
<div>
<?php echo $this->content; ?>
</div>
<div>
footer.phtml
</div>
There are various aproaches to this. Also modules.zendframework has quite a few modules here that may help you out.
If you are still keen on writing that yourself you could add variables to your layout within your controllers like so:
<?php
//YourController.php
public function someAction()
{
...
$this->layout()->footer = 'default';
...
}
//layout.phtml
<?php if ($this->footer === 'default') : ?>
//show the footer
<?php endif; ?>
Doing this is pretty inefficient though. Just imagine you'd need to do this to every action in all the controllers... I sure would not like to do that.
Now zf2 has a service and event layer that could help us out quite a bit here. This is a pretty nice read and introduction to it. You'd just write a service and trigger a event on your controllers/routes/whatever. Now you would also probably like to configure what is shown and what is hidden right? Thats pretty easy, too. Just write yourself a config file and merge it with the global.config like so:
<?php
//CustomModule/module.php
public function getConfig() {
$config = array();
$configFiles = array(
include __DIR__ . '/config/module.config.php',
include __DIR__ . '/config/module.customconfig.php',
);
foreach ($configFiles as $file) {
$config = \Zend\Stdlib\ArrayUtils::merge($config, $file);
}
return $config;
}
Source: Where to put custom settings in Zend Framework 2?
First, get the controller or action name:
$controllerName =$this->params('controller');
$actionName = $this->params('action');
then in your layout/view script add a simple logic.
<?php if ($actionName != 'action that you want to disable the layout/menu'): ?>
echo $this->render('menus.phtml');
<?php endif; ?>
I'm attempting to put a bit of style on a specific set of exposed filters on a view that I have created.
The view is called user_search and so I have created views-exposed-form--user-search.tpl.php and that didn't work (all it did was remove the exposed filters but still displayed the view). views-exposed-form--user-search--page.tpl.php also got the same results.
Even if it did work, I still don't know what to put there to get the form to show up, just so that I can add styles or container divs.
print drupal_render($form); did not work.
I found a solution after a lot of digging.
First, you have to find the views-exposed-form.tpl.php file which should be located in sites/all/modules/views/theme/ folder. We're using the acquia stack so it was located in the vendor/ folder.
Copy this to themes/YOUR-THEME/ folder and rename it to views-exposed-form--your-view-name.tpl.php
If you only want to effect a specific display of your view name it to views-exposed-form--your-view-name--display.tpl.php
You can then use the existing framework to edit it as you see fit. Here's an example.
<?php
// $Id: views-exposed-form.tpl.php,v 1.4.4.1 2009/11/18 20:37:58 merlinofchaos Exp $
/**
* #file views-exposed-form.tpl.php
*
* This template handles the layout of the views exposed filter form.
*
* Variables available:
* - $widgets: An array of exposed form widgets. Each widget contains:
* - $widget->label: The visible label to print. May be optional.
* - $widget->operator: The operator for the widget. May be optional.
* - $widget->widget: The widget itself.
* - $button: The submit button for the form.
*
* #ingroup views_templates
*/
?>
<?php if (!empty($q)): ?>
<?php
// This ensures that, if clean URLs are off, the 'q' is added first so that
// it shows up first in the URL.
print $q;
?>
<?php endif; ?>
<div class="views-exposed-form">
<div class="views-exposed-widgets clear-block">
<?php foreach($widgets as $id => $widget): ?>
<div class="views-exposed-widget">
<?php if (!empty($widget->label)): ?>
<label for="<?php print $widget->id; ?>">
<?php print $widget->label; ?>
</label>
<?php endif; ?>
<?php if (!empty($widget->operator)): ?>
<div class="views-operator">
<?php print $widget->operator; ?>
</div>
<?php endif; ?>
<div class="views-widget">
<?php print $widget->widget; ?>
</div>
</div>
<?php endforeach; ?>
<div class="views-exposed-widget">
<?php print $button ?>
</div>
</div>
</div>
When in doubt about how to theme a part of a page, install the Theme Developer module. It will allow you to see what theme file or function is currently outputting a specific area of the page, as well as what files or functions can be used to override it. See the screencast for more detailed information.
I have a problem with print url on view:
<?php foreach ($rows as $id => $row): ?>
<?php print $row; ?>
<?php
?>
<?php endforeach; ?>
I am getting
Fatal error: Unsupported operand types in /{uri}/includes/common.inc on line 1436
Could somebody help me resolve this error?
Regards
Why you don't use l() function? It's a better solution that build your own link.
http://api.drupal.org/api/drupal/includes%21common.inc/function/l/6