Insert Add blocks in between view results only for S & XS devices - drupal-7

I am using the Drupal 7 - view page with an attachment for displaying articles & featured articles, and i have some Add blocks displays in the right side bar in desktop view. When i move to mobile view( S & XS devices) i need to insert the adds in between view results.
Eg:
views-row-1
views-row-2
views-row-3
<Add Block>
views-row-4
views-row-5
views-row-6
<Add Block>
-------
Note : Ad Blocks created using Doubleclick for Publishers (DFP) module.
Please give me some suggestions on this.
Thanks in Advance.

Create a view field template for your view page. It will looks like this:
sites/all/themes/your_theme/templates/views-view-fields--view-page.tpl.php
views-view-fields--view-page.tpl.php template file will contains this:
$field):
if ($field->class == 'nothing') {
?>
<div class="mobile"> //Remove this class if not mobile version
<?php //this code is to add single addblock, but you can render the all adblock using foreach
$blockObject = block_load('dfp', 'box1');
$block = _block_get_renderable_array(_block_render_blocks(array($blockObject)));
$output = drupal_render($block);
print($output);
?>
</div>
<?php
}
if (!empty($field->separator)): ?>
<?php print $field->separator; ?>
<?php endif; ?>
<?php print $field->wrapper_prefix; ?>
<?php print $field->label_html; ?>
<?php print $field->content; ?>
<?php print $field->wrapper_suffix; ?>
Finally, configure the block, to not show it in your view page (path):
your_domain/admin/structure/block/manage/dfp/block_machine_name/configure
See the last section : Show block on specific pages

Related

How to hide field with label in ctp file in Cakephp?

<div><Strong>Name: </strong><?= $record['Childvaccination']['name']; ?></div>
When data is not coming then it is showing "Name:" only but I also want to hide name if data is not coming or it is empty.
This is cakephp ctp file.
You want to check if the value is empty or not and output accordingly:-
<?php if (!empty($record['Childvaccination']['name'])): ?>
<div><Strong>Name: </strong><?= $record['Childvaccination']['name']; ?></div>
<?php endif; ?>

Drupal7 Solr Search | Views | No Results Template (?)

I'm using Drupal 7's Solr Search Views module to display my search results.
However, when there are no results, there is no message that displays and i can't figure out how to set one and/or where to find the setting that displays it.
Can anyone help with this?
Thanks.
I've gotten the result I wanted by modifying the 'views-view--viewName.tpl.php' like so:
Original (was not showing anything when $empty or no results):
<?php if ($rows): ?>
<?php print $rows; ?>
<?php elseif ($empty): ?>
<?php print $empty; ?>
<?php endif; ?>
New (shows custom message when no results are found):
<?php if ($rows): ?>
<?php print $rows; ?>
<?php else: ?>
<h2>There are no results for this term. Please refine your search.</h2>
<?php endif; ?>
The big difference is the change from 'elseif ($empty):' to a simple 'else:'.

Show Category images in an over-ridden module template

I'm trying to over-ride the default layout template of Categories list within the Module
mod_articles_categories
The reason for that is to be able to display the images associated with each category which is set in the params of each category.
The code that I found to show those images is
json_decode($item->params)->image
But it's not working, any ideas?
The "official" way would be to use something like this within the foreach ($list as $item) :
<?php
$params = new JRegistry();
$params->loadString($item->params);
$image = $params->get('image');
if ($image) : ?>
<img src="<?php echo $image; ?>" />
<?php endif; ?>
But you code should work as well. At least it does when I tested it locally. The code I posted would allow you to set a default value for the param. Like $params->get('image', 'foo/bar.png');. Other than that it does about the same.

How do i use batch insert in yii

Please i need a big help here. AM developing a yii application where i have to loop through my form and do a batch insert. I found bacth update in yii but ive not been able to see how to do batch insert and validation. Please help.
Here is my View:
<?php for($i=0;$i< $this->getDisplayArchModel();$i++) {?>
<FIELDSET class="radios">
<div class="row">
<?php echo $form->labelEx($model,'competency_type'); ?>
<?php echo $form->textField($model,'competency_type'); ?>
<?php echo $form->error($model,'competency_type'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'definition'); ?>
<?php echo $form->textArea($model,'definition'); ?>
<?php echo $form->error($model,'definition'); ?>
</div>
</fieldset>
<?php } ?>
Controller ::
public function actionDisplayArchModel()
{
$validateCat = $this->getDisplayArchModel();
if($validateCat == NULL)
$this->redirect(array('architecture'));
$model = new CompetencyType;
if(isset($_POST['CompetencyType']))
{
$model->attributes = $_POST['CompetencyType'];
if($model->validate()){
foreach($_POST['CompetencyType'] as $value)
{
echo $value;
}
}
}
$this->render('displayArchModel' ,array('model'=>$model));
}
Sometimes we want to collect user input in a batch mode. That is, the user can enter the information for multiple model instances and submit them all at once. We call this tabular input because the input fields are often presented in an HTML table.
To work with tabular input, we first need to create or populate an array of model instances, depending on whether we are inserting or updating the data. We then retrieve the user input data from the $_POST variable and assign it to each model. A slight difference from single model input is that we retrieve the input data using $_POST['ModelClass'][$i] instead of $_POST['ModelClass'].
more on collecting Tabular Input

Magento product display text "array" instead of multiple values

On my Magento product page; when a product has multiple values for one custom attribute; instead of displaying the values it displays the text "array". It works fine with one value.
Thanks,
-Sam
You can do something like:
<?php
foreach($_product->getMetal() as $name => $value): ?>
<?php echo $name;?> = <?php echo $value;?>
<?php
endforeach; ?>
Magento takes advantage of PHP's magic getter/setter functionality (http://www.php.net/manual/en/language.oop5.overloading.php#object.get).
You can do a vardump($_product) to see the available attributes (they are stored in the _data array in the product). Then to retrieve one of them, you just remove the underscores and change the first letter of each word to uppercase.
EDIT:
If the above code doesn't output values, you can do this (which will tell you how to get to the value):
<?php
foreach($_product->getMetal() as $attribute): ?>
<?php var_dump($attribute); ?>
<?php
endforeach; ?>
I found this on Magento forums and it seems to work:
` getData('attribute_name')): ?>
getResource()->getAttribute('attribute_name')->getFrontend()->getValue($_product)) ?>
`

Resources