Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls
 

Flexy conditional statements

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 06-12-2015, 09:39 AM
 
xgarb xgarb is offline
 

eXpert
  
Join Date: Jul 2004
Location: UK
Posts: 263
 

Default Flexy conditional statements

As part of making the thumbnails larger and responsive I want to remove the fixed height and width parts of the generated image tag.

I've done this...

Code:
<img style="width:100%; height:100%" src="{getURL()}" alt="{getAlt()}" {foreach:getProperties(),name,value} {if:#width#={name}} {elseif:#height#={name}} {else:} {name}="{value}" {end:} {end:} />

but it seems a bit hacky and produces bad mark up in the cache...

Code:
<?php if ('width'==$this->get('name')){?>} <?php }elseif ('height'==$this->get('name')){?>} <?php }else{ ?> <?php echo func_htmlspecialchars($this->get('name')); ?>="<?php echo func_htmlspecialchars($this->get('value')); ?>" <?php }?>

It does however work and produce the correct HTML.

Could I improve it?
__________________
Core version: 5.5.xx
Reply With Quote
  #2  
Old 06-15-2015, 05:12 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,431
 

Default Re: Flexy conditional statements

Hello @xgarb

You can create a method that will take two params (name, value) and incorporate this logic into it:

Code:
{if:#width#={name}} {elseif:#height#={name}} {else:} {name}="{value}" {end:}

so it would look as follows:

Code:
{foreach:getProperties(),name,value} {displayImageDimension(name, value)} {end:}

Hopefully, it helps.

Tony
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote
  #3  
Old 06-15-2015, 07:09 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Flexy conditional statements

I think the better way would be extending the getProperties() method and removing/adding tag properties from there as follows (I used Custom Skin as the module for implementing the change, you can use your custom module):
PHP Code:
<?php
// file: classes\XLite\Module\XC\CustomSkin\View\Image.php

namespace XLite\Module\XC\CustomSkin\View;

class 
Image extends \XLite\View\Image implements \XLite\Base\IDecorator
{
    public function 
getProperties()
    {
        
$properties parent::getProperties();

        
$properties['style'] .= 'width: 100%; height: auto;' . (isset($properties['style']) ? $properties['style'] : '');
        unset(
$properties['width']);
        unset(
$properties['height']);

        
$this->properties $properties;

        return 
$properties;
    }

}

As you don't replace the template file, this method would be more future proof (compatible with future upgrades).
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
  #4  
Old 06-15-2015, 07:11 AM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

X-Guru
  
Join Date: Dec 2010
Posts: 6,373
 

Default Re: Flexy conditional statements

Quote:
style="width:100%; height:100%"

This won't make the images responsive, but will resize them without keeping the aspect rate. The styles should be either "width:100%; height: auto", or "height:100%;width:auto".
__________________
Alex Solovev,
Qualiteam

---

User manual Video tutorials X-Cart FAQ

You are welcome to press "Thanks" button
if you find this post useful

Click here to learn how to apply patches

X-Cart Extensions
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 12:50 PM.

   

 
X-Cart forums © 2001-2020