I have a custom template that renderes a module in some position. The module does a query to database and renders according to the results. However, if the query to database returns empty rows, module does not have to be shown.
I have this in the template:
<!-- lo más de la semana -->
<?php if ($this->countModules('lo-mas') > 0): ?>
<div class="row">
<div class="lomas"> <h3>LO MÁS DE LA SEMANA</h3></div>
<jdoc:include type="modules" name="lo-mas" />
</div>
<?php endif; ?>
<!-- fin lo más de la semana -->
I can have several modules at "lo-mas" position, but if, for some reason, all of the modules does not render any output, I don't want the title to be shown ("LO MÁS DE LA SEMANA")
Is this possible in Joomla 3?
I think you can solve this by rendering the modules a little more manually:
<?php
jimport( 'joomla.application.module.helper' );
$modules = JModuleHelper::getModules( 'lo-mas' );
$output = '';
foreach ($modules as $module) {
$output .= JModuleHelper::renderModule($module);
}
if (trim($output)){
?>
<div class="row">
<div class="lomas"> <h3>LO MÁS DE LA SEMANA</h3></div>
<?php echo $output; ?>
</div>
<?php
}
?>
You can probably decide exactly how your modules are rendered by specifying the style somehow (usually xhtml), and applying some more html-code to the output...
Related
I must add checkbox in Contact form in Magetno (Magento wer. 1.8.1), I searching tutorials on Google but I found solution ... It is easy way to do this ?
Many Thanks
Wojtek
why you don't use the checkout agreements: Just fetch the agreements in file \app\design\frontend\PACKAGE\TEMPLATE\template\contacts\form.phtml by
if (Mage::getStoreConfigFlag('checkout/options/enable_agreements')) {
$agreements = Mage::getModel('checkout/agreement')->getCollection()
->addStoreFilter(Mage::app()->getStore()->getId())
->addFieldToFilter('is_active', 1);
}
and print out some or all of them like
if ($agreements) {
foreach ($agreements as $_a):
// ID 5 = Datenschutz-Agreement deutsch, ID 6 = Alter-18-Agreement englisch, ID 7 = Datenschutz-Agreement deutsch, ID 8 = Alter-18-Agreement englisch
if ($_a->getId() >= 7 && $_a->getId() <= 8) {
?>
<li>
<div class="checkout-agreements">
<div class="agreement-content"<?php echo ($_a->getContentHeight() ? ' style="height:' . $_a->getContentHeight() . '"' : '')?>>
<?php if ($_a->getIsHtml()):?>
<?php echo $_a->getContent() ?>
<?php else:?>
<?php echo nl2br($this->escapeHtml($_a->getContent())) ?>
<?php endif; ?>
</div>
<p class="agree">
<input type="checkbox" id="agreement-<?php echo $_a->getId()?>" name="agreement[<?php echo $_a->getId()?>]" value="1" title="<?php echo $this->escapeHtml($_a->getCheckboxText()) ?>" class="required-entry checkbox" /><label for="agreement-<?php echo $_a->getId()?>"><?php echo $_a->getIsHtml() ? $_a->getCheckboxText() : $this->escapeHtml($_a->getCheckboxText()) ?></label>
</p>
</div>
</li>
<?php
}
endforeach;
}
That's all!
If there is someone German here: There you will get the full explanation in German!
Best regards
Bastian
In Magento 2.0, the default has the layered navigation all collapsed except for the first filter, which is Prices for me. How do I expand all the filters so that each filter option is visible in all filter categories?
I see in the code there's aria-expanded="false" and in the HTML somewhere there is class="filter-options-content" with style="display: none;"
Anyone know where to edit this?
If you are using the Luma theme and want to do this make sure to create your own theme as a child of the Luma theme. You can find more information on that here (https://community.magento.com/t5/Theming-Layout-Design-Questions/How-to-create-a-Child-Theme-in-Magento-2/m-p/33314#M384)
Then, copy the file located at "vendor\magento\theme-frontend-luma\Magento_LayeredNavigation\templates\layer\view.phtml" into the appropriate area in your child theme.
You need to change the data-mage-init attribute and the "active" property to be in a format that specifies which filters to open by their index. I have 6 filters, so I want that property to read "0 1 2 3 4 5".
I made a couple of changes between lines 30-45 and it looks like this:
<?php $wrapOptions = false; ?>
<?php
$filters = $block->getFilters();
$active_filters_str = implode(' ', range(0, count($filters)-1));
?>
<?php foreach ($filters as $filter): ?>
<?php if ($filter->getItemsCount()): ?>
<?php if (!$wrapOptions): ?>
<div class="filter-options" id="narrow-by-list" data-role="content" data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": "<?php echo $active_filters_str ?>", "multipleCollapsible": true}}'>
<?php $wrapOptions = true; endif; ?>
<div data-role="collapsible" class="filter-options-item">
<div data-role="title" class="filter-options-title"><?php /* #escapeNotVerified */ echo __($filter->getName()) ?></div>
<div data-role="content" class="filter-options-content"><?php /* #escapeNotVerified */ echo $block->getChildBlock('renderer')->render($filter); ?></div>
</div>
<?php endif; ?>
<?php endforeach; ?>
First, make sure to get all of the filters in a variable with "$filters = $block->getFilters();". Then, create a string for the active property listing them out by index using the "$active_filters_str = implode(' ', range(0, count($filters)-1));" Then echo this next to the active property in the mage-init attribute.
Hope this helps :)
https://magento.stackexchange.com/questions/102259/open-category-filters-by-default-in-magento-2
OPEN FILE :##
vendor\magento\theme-frontend-luma\Magento_LayeredNavigation\templates\layer\view.phtml
And change the 'data-mage-init' attribute as follow:
<?php foreach ($block->getFilters() as $filter): ?>
<?php if ($filter->getItemsCount()): ?>
<?php if (!$wrapOptions): ?>
<?php $collapsibleRange = implode(' ', range(0, $filter->getItemsCount())); ?>
<strong role="heading" aria-level="2" class="block-subtitle filter-subtitle"><?php /* #escapeNotVerified */ echo __('Shopping Options') ?></strong>
<div class="filter-options" id="narrow-by-list" data-role="content" data-mage-init='{"accordion":{"openedState": "active", "collapsible": true, "active": "<?php echo $collapsibleRange ?>", "multipleCollapsible": true}}'>
<?php $wrapOptions = true; endif; ?>
<div data-role="collapsible" class="filter-options-item">
<div data-role="title" class="filter-options-title"><?php /* #escapeNotVerified */ echo __($filter->getName()) ?></div>
<div data-role="content" class="filter-options-content"><?php /* #escapeNotVerified */ echo $block->getChildBlock('renderer')->render($filter); ?></div>
</div>
<?php endif; ?>
In Magento 1 I've always used
$_product->getMediaGallery('images')
But in the source from Magento 2 I see
$productImage = $block->getImage($_product, $image);
echo $productImage->toHtml();
It's only getting the first product image.
How do I get the second or third image (not only the base one)?
GetMediaGallery function doesn't exists?
Step 1 : open list.phtml from Your Theme\Magento_Catalog\templates\product
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$_imagehelper = $this->helper('Magento\Catalog\Helper\Image');
Add above in your phtml file
then add below code in product loop where you want gallery images
<div class="left-carousel">
<div class="product-small-thumbs">
<?php $product = $objectManager->create('Magento\Catalog\Model\Product')->load($_product->getId());
$images = $product->getMediaGalleryImages();
if($images->count()>0){?>
<div class="carousel carousel-<?php $_product->getId()?>">
<?php
$i = 0;
foreach($images as $child){
$i++;
$productImage = $_imagehelper->init($product, 'product_page_image_large')
->setImageFile($child->getFile())->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(TRUE)->resize(81,53)
->getUrl();
$productImagedata = $_imagehelper->init($product, 'product_page_image_large')
->setImageFile($child->getFile())->constrainOnly(FALSE)->keepAspectRatio(TRUE)->keepFrame(TRUE)->resize(285,240)
->getUrl();
if($i==1) continue;
?>
<div class="slide">
<img data-id="smallthumbs-<?php echo $_product->getId();?>" data-img="<?php echo $productImagedata; ?>" src="<?php echo $productImage; ?>"/>
</div>
<?php
}
?>
</div>
<?php
}
?>
</div>
</div>
I'm new at this and some help will be apprciated.
I'm building a sidebar in a CI-Boilerplate-Project which contains modules (widgets) that i got run with HMVC https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc.
In the sidebar i have a widget that display a friendslist with status online/offline.
The user has the ability to switch the widgets on/off in the managementsection.
In the Profileview:
<aside class="sidebox right">
<?php foreach ($boxes as $boxName => $boxSetting)
{
echo Modules::run($boxName, $boxSetting['box_visible']);
}
?>
</aside>
if box_visible == 1 the widget will be displayed.
Controller:
class Myfriends extends SM_Controller
{
function __construct()
{
parent::__construct();
}
public function index($visible = false)
{
$user = $this->session->userdata('user');
$myf = $this->widget_model->get_friends($user['user_id'], 5);
$data['friends'] = $myf;
if ($visible) $this->load->view('myfriends', $data);
}
}
View:
<html>
<head>
<meta http-equiv="refresh" content="5">
</head>
<body>
<div class="box friendsbox">
<div id="header"><h3><?=$boxTitle?></h3></div>
<div id="boxcontent">
<ul>
<?php foreach ($friends as $friend): ?>
<li>
<div id="thb_img">
<img src="<?=img_thumb($friend['file_path'], 50, 50) ?>" />
</div>
<div id="short_desc">
<a href="<?= site_url('widget_functions/show_user/' . $friend['uu_id']) ?>">
<?= ucfirst($friend['user_name']) . ' ' . ucfirst($friend['user_lastname']) . ' ' ?>
</a>
<?php if ($friend['is_online']): ?>
<span style="color: green">online</span>
<?php endif; ?>
</div>
</li>
<?php endforeach; ?>
</ul>
</div>
<div id="footer">» mehr</div>
</div>
</body>
</html>
Now, i need to update the friendslist every 1-2 min so i tryed to load the moduleview within an iframe:
<aside class="sidebox right">
<?php foreach ($boxes as $boxName => $boxSetting): ?>
<?php if ($boxName == 'myfriends' && $boxSetting['box_visible'] == 1) { ?>
<iframe src="<?php echo site_url('myfriends/index'); ?>" ></iframe>
<?php
}
else
{
echo Modules::run($boxName, $boxSetting['box_visible']);
}
?>
<?php endforeach; ?>
</aside>
BUT this dose not work! The place of the widget is emtpy.
Do you have any idea how to get that to work?
appreciate your help
I believe the main issue is with the way you initialize the index method. the index method is kinda tricky with parameters in Codeigniter. In my projects, the only way to get the vlues of arguments passed to the index parameters is by using the URI library method $this->uri->segment(n). In other words, I believe that the value of $visible is not properly passing to the index() body
Anyway, I think you should create another method in your MyFriends Class called render() for example, and call it instead of relaying on the index() method. now render() can play nicely with the $visible=false initialization trick.
Hope this helps
I'm trying to display category description only on the first page. The following code is not working - any idea how to fix it?
<div class="category-description std">
<?php
if (strlen($_SERVER['QUERY_STRING']) = 0 || $_GET['p'] = '1')
{
echo $_helper->categoryAttribute($_category, $_description, 'description');
}
?>
</div>
Please try this one :
<?php if($_description=$this->getCurrentCategory()->getDescription()): ?>
<?php $currentPage = (int) Mage::App()->getRequest()->getParam('p');
if($currentPage <= 1):
?>
<div class="category-description std">
<?php echo $_helper->categoryAttribute($_category, $_description, 'description') ?>
</div>
<?php endif; ?>
<?php endif; ?>'
You can use the products list toolbar to know if you're on the first page :
if ($this->isContentMode()
|| $this->getChild('product_list')->getToolbarBlock()->isFirstPage()) {
// Display description (assuming that content mode is always first page)
}