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

Show/hide in template with flexy If statement and config data

 
Reply
   X-Cart forums > X-Cart 5 > Dev Questions (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 03-10-2016, 09:56 AM
 
xgarb xgarb is online now
 

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

Default Show/hide in template with flexy If statement and config data

Following the example here:

http://kb.x-cart.com/display/XDD/Flexy+Guide

I have this in my template: {if:getWidth()} width="{getWidth()}" {end:}

I want to show width="{getWidth()" in my template only if getWidth has been set.


The method looks like this:
Code:
public function getWidth() { return \XLite\Core\Config::getInstance()->Tienda->myWidget->data_width; }

where data_width is a user setting in the admin area of the widget. If this setting is left blank, I don't want the text in italics above to show.

I've tried return false and NULL and the text is still shown. Is my only option to use != or <> '' in the IF statement?
__________________
Core version: 5.5.xx
Reply With Quote
  #2  
Old 03-12-2016, 07:08 AM
  totaltec's Avatar 
totaltec totaltec is offline
 

X-Guru
  
Join Date: Jan 2007
Location: Louisville, KY USA
Posts: 5,823
 

Default Re: Show/hide in template with flexy If statement and config data

Is it possible that the getWidth method is pulling from somewhere else?

If you are returning false, it seems that your code above should be working.
__________________
Mike White - Now Accepting new clients and projects! Work with the best, get a US based development team for just $125 an hour. Call 1-502-773-6454, email mike at babymonkeystudios.com, or skype b8bym0nkey

XcartGuru
X-cart Tutorials | X-cart 5 Tutorials

Check out the responsive template for X-cart.
Reply With Quote
  #3  
Old 03-12-2016, 07:49 AM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 14,191
 

Default Re: Show/hide in template with flexy If statement and config data

I think you need 2 functions - one to check if the width is set and another to return actual width. The if statement works with true/false values

Code:
{if:isWidthSet()} width="{getWidth()}" {end:} public function isWidthSet() { return !empty(\XLite\Core\Config::getInstance()->Tienda->myWidget->data_width); } public function getWidth() { return \XLite\Core\Config::getInstance()->Tienda->myWidget->data_width; }
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote

The following user thanks cflsystems for this useful post:
qualiteam (03-13-2016)
  #4  
Old 03-13-2016, 09:17 AM
 
xgarb xgarb is online now
 

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

Default Re: Show/hide in template with flexy If statement and config data

I must have been doing something wrong somewhere as now a simple function like..

Code:
public function getWidth() { return \XLite\Core\Config::getInstance()->Tienda->myWidget->data_width; }

with
Code:
{if:getWidth()}width="{getWidth()}"{end:}
in the template is working perfectly.

If the option is left blank in the module settings then the whole line isn't shown.

I thought I might need something a little more complex like
Code:
public function getWidth() { $dataWidth = \XLite\Core\Config::getInstance()->Tienda->myWidget->data_width; return !empty($dataWidth) ? $dataWidth : false; }
but it doesn't seem necessary.
__________________
Core version: 5.5.xx
Reply With Quote

The following user thanks xgarb for this useful post:
qualiteam (03-13-2016)
  #5  
Old 03-13-2016, 08:44 PM
  qualiteam's Avatar 
qualiteam qualiteam is offline
 

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

Default Re: Show/hide in template with flexy If statement and config data

For simple cases like this, when you need to check if a module setting is configured, a single method should be enough.

For more complex cases it is recommended to have the second method so that it could be extended and tweaked from another module (when needed).
__________________
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 05:47 AM.

   

 
X-Cart forums © 2001-2020