I have an if statement that is at the end of a for each loop that adds the | character at the end of a generated unordered list.
My goal is to add | after "not the last two".
<?php if (! $_link->getIsLast()):?>|<?php endif;?>
I was hoping I could input a value in the getIsLast or getIsFirst functions like this:
<?php if (! $_link->getIsLast(2)):?>|<?php endif;?>
I was hoping the above statement would add the | character for each generated list item except for the last two. However, it doesn't seem to be working.
Does anyone know the proper syntax to do something like this?
The for each loops is below:
<ul class="links pull-right"<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?>>
<?php foreach($_links as $_link): ?>
<?php if ($_link instanceof Mage_Core_Block_Abstract):?>
<?php echo $_link->toHtml() ?>
<?php else: ?>
<li<?php if($_link->getIsFirst()||$_link->getIsLast()): ?> class="<?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
<?php endif;?>
<?php if (! $_link->getIsLast()):?>|<?php endif;?>
<?php endforeach; ?>
</ul>
Try this.
<ul class="links pull-right"<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?>>
<?php
$numberOfRows = count($_links);
$currentIndex=0;
foreach($_links as $_link):
?>
<?php if ($_link instanceof Mage_Core_Block_Abstract):?>
<?php echo $_link->toHtml() ?>
<?php else: ?>
<li<?php if($_link->getIsFirst()||$_link->getIsLast()): ?> class="<?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
<?php endif;?>
<?php if ($currentIndex<$numberOfRows-2):?>|<?php endif;?>
<?php
$currentIndex++;
endforeach; ?>
</ul>
|
Related
I'm working on a Magento site which is using the Fishpig Wordpress Extension. We have the Categories widget displaying in the left sidebar & it is set to show hierarchy.
It is working two levels deep (i.e. ul & li's with .level0 & .level1), but is not showing categories 3 levels deep i.e. level2
I've tested this on a basic wordpress installation and I can get it to display categories 3 levels down but I can't get it to work on Magento with the fishpig WordPress integration. I have assigned posts to all the sub categories.
I see in template/wordpress/sidebar/widget/categories.phtml that there is this code block to get the level1 child categories:
<?php else: ?>
<?php foreach($categories as $category): ?>
<li class="level0 item<?php if ($this->isCurrentCategory($category)): ?> active<?php endif; ?>">
<a class="level0" href="<?php echo $category->getUrl() ?>" title="<?php echo $category->getName() ?>">
<?php echo $category->getName() ?>
</a><?php if ($this->getCount()): ?> (<?php echo $category->getPostCount() ?>)<?php endif; ?>
<?php if ($this->getHierarchical()): ?>
<?php $children = $children = $category->getChildrenCategories() ?>
<?php if (count($children) > 0): ?>
<ul class="level1">
<?php foreach($children as $child): ?>
<?php if ($child->getPostCount() > 0): ?>
<li class="level1 item<?php if ($this->isCurrentCategory($child)): ?> active<?php endif; ?>">
» <?php echo $child->getName() ?><?php if ($this->getCount()): ?> (<?php echo $child->getPostCount() ?>)<?php endif; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
<?php endif; ?>
Is there a way to display more than two levels of wordpress categories on Magento with Fishpig?
I updated template/wordpress/sidebar/widget/categories.phtml to include a 3rd level and it worked :)
<?php foreach($categories as $category): ?>
<li class="level0 item<?php if ($this->isCurrentCategory($category)): ?> active<?php endif; ?>">
<a class="level0" href="<?php echo $category->getUrl() ?>" title="<?php echo $category->getName() ?>">
<?php echo $category->getName() ?>
</a><?php if ($this->getCount()): ?> (<?php echo $category->getPostCount() ?>)<?php endif; ?>
<?php if ($this->getHierarchical()): ?>
<?php $children = $children = $category->getChildrenCategories() ?>
<?php if (count($children) > 0): ?>
<ul class="level1">
<?php foreach($children as $child): ?>
<?php if ($child->getPostCount() > 0): ?>
<li class="level1 item<?php if ($this->isCurrentCategory($child)): ?> active<?php endif; ?>">
» <?php echo $child->getName() ?><?php if ($this->getCount()): ?> (<?php echo $child->getPostCount() ?>)<?php endif; ?>
<?php $children2 = $children2 = $child->getChildrenCategories() ?>
<?php if (count($children2) > 0): ?>
<ul class="level2">
<?php foreach($children2 as $child2): ?>
<?php if ($child2->getPostCount() > 0): ?>
<li class="level12 item<?php if ($this->isCurrentCategory($child2)): ?> active<?php endif; ?>">
» <?php echo $child2->getName() ?><?php if ($this->getCount()): ?> (<?php echo $child2->getPostCount() ?>)<?php endif; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
I have this list:
And I wanted to add the " | " character between the links in blue.
However, the list items are generated by PHP in the following code:
<ul class="links pull-right"<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?>>
<?php foreach($_links as $_link): ?>
<?php if ($_link instanceof Mage_Core_Block_Abstract):?>
<?php echo $_link->toHtml() ?>
<?php else: ?>
<li<?php if($_link->getIsFirst()||$_link->getIsLast()): ?> class="<?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
<?php endif;?> | //----------- the | character was added here ---------------
<?php endforeach; ?>
</ul>
The problems are:
the PHP is in a for each loop and the | character is added to the last link as well.
I want to position the "Log In" somewhere else on my page. Is there a way to separate the last list item and position it elsewhere?
Any help is greatly appreciated!
For 1:
Use $_link->getIsLast(). Check if it is not last -> Add your Delimiter.
<ul class="links pull-right"<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?>>
<?php foreach($_links as $_link): ?>
<?php if ($_link instanceof Mage_Core_Block_Abstract):?>
<?php echo $_link->toHtml() ?>
<?php else: ?>
<li<?php if($_link->getIsFirst()||$_link->getIsLast()): ?> class="<?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
<?php endif;?>
<?php if (! $_link->getIsLast()):?>|<?php endif;?> //----------- the | character was added here ---------------
<?php endforeach; ?>
</ul>
That Should Work.
EDIT:
For Number 2:
Not 100% sure. Probably have to disable that link, then manually add it/its block's url to your layout/.phtml.
Because the link generation is automated so you would have to disable the link and then call $something->getUrl()
SIMILAR Wishlist
From: Magento add wishlist_link to different block?
Really need some help after many hours of banging head against a brick wall!
Basically I have a Joomla News page made in the K2 component. The page would have the top story, the next two, then the next four and the next four after that all with their own class so they can be styled differently for emphasis (like most news websites).
So there would be one row of one column - main news (with items image and text cut off after about 150 words with a 'read more')
second row - two columns - next two news pieces (with items image and text cut off after about 150 words with a 'read more')
third row - four columns - next four news pieces (with items image and text cut off after about 150 words with a 'read more')
fourth row - one column of eight links (no image just the title linked)
This is the file I'm trying to amend:
<?php
// no direct access
defined('_JEXEC') or die;
$selectedFilters=$params->get('extraFieldsSelect'); //get selected fields in module params
?>
<div id="k2ModuleBox<?php echo $module->id; ?> k2FiltrifyContainer" class="k2Filtrify k2ItemsBlock<?php if($params->get('moduleclass_sfx')) echo ' '.$params->get('moduleclass_sfx'); ?>">
<?php if($params->get('itemPreText')): ?>
<p class="modulePretext"><?php echo $params->get('itemPreText'); ?></p>
<?php endif; ?>
<!--Filtrify Placeholder-->
<div id="k2FiltrifyPlaceHolder"></div>
<?php //set placeholder, if LEGEND is the selected callback method
if($placeholder == 'legend'): ?>
<!--Filtrify legend placeholder-->
<div id="legend"><i><?php echo JText::_('K2_VIEWING_ALL'); ?></i></div>
<?php endif; ?>
<?php //set placeholder, if PAGINATION is the selected callback method
if($placeholder == 'pagination'): ?>
<!--Filtrify pagination placeholder-->
<div id="pagination"></div>
<?php endif; ?>
<?php if(count($items)): //Filtrify Container?>
<ul id="k2FiltrifyContainer">
<p>
<?php foreach ($items as $keyItem=>$item): ?>
<?php
// Define a CSS class for the last container on each row
if( (($keyItem+1)%($params->get('num_columns'))==0) || count($items)<$params->get('num_columns') )
$lastContainer= ' itemContainerLast';
else
$lastContainer='';
?>
<li class="itemContainer<?php echo $lastContainer; ?>" <?php echo (count($items)==1) ? '' : ' style="width:'.number_format(100/$params->get('num_columns'), 1).'%;"'; ?>
<?php
if( count($item->extra_fields) && $selectedFilters != ''): //check if there are extrafields and selected fields?>
<?php foreach ($item->extra_fields as $key=>$extraField): //adding extrafields as data parameter?>
<?php if(in_array($extraField->id,(array)$selectedFilters, TRUE)) : ?>
data-<?php echo preg_replace("/[^A-Za-zA-yA-y0-9а-яА-Яa-zA-Z?-??-?sctzlldSCTZLD]/ui", "_", $extraField->name); ?>="<?php echo $extraField->value; //set the values, and remove special chars?>"
<?php endif; ?>
<?php endforeach; ?>
<?php endif; ?>
<?php if($params->get('showCatFilter')==1): //check for param - show category filter?>
data-<?php echo preg_replace("/[^A-Za-zA-yA-y0-9а-яА-Яá-źÁ-ŹΑ-Ωα-ωščťžľĺďŠČŤŽĹĎ]/ui", "_", JText::_('K2_CATEGORIES')); ?>="<?php echo $item->categoryname;?>"
<?php endif; ?>
<?php if($params->get('showTagFilter')==1): //check for param - show tag filter?>
data-<?php echo preg_replace("/[^A-Za-zA-yA-y0-9а-яА-Яá-źÁ-ŹΑ-Ωα-ωščťžľĺďŠČŤŽĹĎ]/ui", "_", JText::_('K2_TAGS')); ?>="<?php foreach ($item->tags as $tag): ?><?php echo $tag->name; ?>, <?php endforeach; ?>"
<?php endif; ?>
>
</p>
<p>
<?php if(isset($item->event->BeforeDisplay)): ?>
<!-- Plugins: BeforeDisplay -->
<?php echo $item->event->BeforeDisplay; ?>
<?php endif; ?>
<!-- K2 Plugins: K2BeforeDisplay -->
<?php echo $item->event->K2BeforeDisplay; ?>
<?php if($params->get('itemAuthorAvatar')): ?>
<a class="k2Avatar moduleItemAuthorAvatar" rel="author" href="<?php echo $item->authorLink; ?>">
<img src="<?php echo $item->authorAvatar; ?>" alt="<?php echo K2HelperUtilities::cleanHtml($item->author); ?>" style="width:<?php echo $avatarWidth; ?>px;height:auto;" />
</a>
<?php endif; ?>
<?php if($params->get('itemTitle')): ?>
<a class="moduleItemTitle" href="<?php echo $item->link; ?>"><?php echo $item->title; ?></a>
<?php endif; ?>
<?php if($params->get('itemAuthor')): ?>
</p>
<div class="moduleItemAuthor">
<?php echo K2HelperUtilities::writtenBy($item->authorGender); ?>
<?php if(isset($item->authorLink)): ?>
<a rel="author" title="<?php echo K2HelperUtilities::cleanHtml($item->author); ?>" href="<?php echo $item->authorLink; ?>"><?php echo $item->author; ?></a>
<?php else: ?>
<?php echo $item->author; ?>
<?php endif; ?>
<?php if($params->get('userDescription')): ?>
<?php echo $item->authorDescription; ?>
<?php endif; ?>
</div>
<?php endif; ?>
<?php if(isset($item->event->AfterDisplayTitle)): ?>
<!-- Plugins: AfterDisplayTitle -->
<?php echo $item->event->AfterDisplayTitle; ?>
<?php endif; ?>
<!-- K2 Plugins: K2AfterDisplayTitle -->
<?php echo $item->event->K2AfterDisplayTitle; ?>
<?php if(isset($item->event->BeforeDisplayContent)): ?>
<!-- Plugins: BeforeDisplayContent -->
<?php echo $item->event->BeforeDisplayContent; ?>
<?php endif; ?>
<!-- K2 Plugins: K2BeforeDisplayContent -->
<?php echo $item->event->K2BeforeDisplayContent; ?>
<?php if($params->get('itemImage') || $params->get('itemIntroText')): ?>
<div class="moduleItemIntrotext">
<?php if($params->get('itemImage') && isset($item->image)): ?>
<a class="moduleItemImage" href="<?php echo $item->link; ?>" title="<?php echo JText::_('K2_CONTINUE_READING'); ?> "<?php echo K2HelperUtilities::cleanHtml($item->title); ?>"">
<img src="<?php echo $item->image; ?>" alt="<?php echo K2HelperUtilities::cleanHtml($item->title); ?>"/>
</a>
<?php endif; ?>
<?php if($params->get('itemIntroText')): ?>
<?php echo $item->introtext; ?>
<?php endif; ?>
</div>
<?php endif; ?>
<div class="clr"></div>
<?php if($params->get('itemExtraFields') && count($item->extra_fields)): ?>
<div class="moduleItemExtraFields">
<b><?php echo JText::_('K2_ADDITIONAL_INFO'); ?></b>
<ul>
<?php foreach ($item->extra_fields as $extraField): ?>
<?php if($extraField->value): ?>
<li class="type<?php echo ucfirst($extraField->type); ?> group<?php echo $extraField->group; ?>">
<span class="moduleItemExtraFieldsLabel"><?php echo $extraField->name; ?></span>
<span class="moduleItemExtraFieldsValue"><?php echo $extraField->value; ?></span>
<div class="clr"></div>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
<div class="clr"></div>
<?php if($params->get('itemVideo')): ?>
<div class="moduleItemVideo">
<?php echo $item->video ; ?>
<span class="moduleItemVideoCaption"><?php echo $item->video_caption ; ?></span>
<span class="moduleItemVideoCredits"><?php echo $item->video_credits ; ?></span>
</div>
<?php endif; ?>
<div class="clr"></div>
<?php if(isset($item->event->AfterDisplayContent)): ?>
<!-- Plugins: AfterDisplayContent -->
<?php echo $item->event->AfterDisplayContent; ?>
<?php endif; ?>
<!-- K2 Plugins: K2AfterDisplayContent -->
<?php echo $item->event->K2AfterDisplayContent; ?>
<?php if($params->get('itemDateCreated')): ?>
<span class="moduleItemDateCreated"><?php echo JText::_('K2_WRITTEN_ON') ; ?> <?php echo JHTML::_('date', $item->created, JText::_('K2_DATE_FORMAT_LC2')); ?></span>
<?php endif; ?>
<?php if($params->get('itemCategory')): ?>
<?php echo JText::_('K2_IN') ; ?> <a class="moduleItemCategory" href="<?php echo $item->categoryLink; ?>"><?php echo $item->categoryname; ?></a>
<?php endif; ?>
<?php if($params->get('itemTags') && count($item->tags)>0): ?>
<div class="moduleItemTags">
<b><?php echo JText::_('K2_TAGS'); ?>:</b>
<?php foreach ($item->tags as $tag): ?>
<?php echo $tag->name; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if($params->get('itemAttachments') && count($item->attachments)): ?>
<div class="moduleAttachments">
<?php foreach ($item->attachments as $attachment): ?>
<a title="<?php echo K2HelperUtilities::cleanHtml($attachment->titleAttribute); ?>" href="<?php echo $attachment->link; ?>"><?php echo $attachment->title; ?></a>
<?php endforeach; ?>
</div>
<?php endif; ?>
<?php if($params->get('itemCommentsCounter') && $componentParams->get('comments')): ?>
<?php if(!empty($item->event->K2CommentsCounter)): ?>
<!-- K2 Plugins: K2CommentsCounter -->
<?php echo $item->event->K2CommentsCounter; ?>
<?php else: ?>
<?php if($item->numOfComments>0): ?>
<a class="moduleItemComments" href="<?php echo $item->link.'#itemCommentsAnchor'; ?>">
<?php echo $item->numOfComments; ?> <?php if($item->numOfComments>1) echo JText::_('K2_COMMENTS'); else echo JText::_('K2_COMMENT'); ?>
</a>
<?php else: ?>
<a class="moduleItemComments" href="<?php echo $item->link.'#itemCommentsAnchor'; ?>">
<?php echo JText::_('K2_BE_THE_FIRST_TO_COMMENT'); ?>
</a>
<?php endif; ?>
<?php endif; ?>
<?php endif; ?>
<?php if($params->get('itemHits')): ?>
<span class="moduleItemHits">
<?php echo JText::_('K2_READ'); ?> <?php echo $item->hits; ?> <?php echo JText::_('K2_TIMES'); ?>
</span>
<?php endif; ?>
<?php if($params->get('itemReadMore') && $item->fulltext): ?>
<a class="moduleItemReadMore" href="<?php echo $item->link; ?>">
<?php echo JText::_('K2_READ_MORE'); ?>
</a>
<?php endif; ?>
<?php if(isset($item->event->AfterDisplay)): ?>
<!-- Plugins: AfterDisplayContent -->
<?php echo $item->event->AfterDisplay; ?>
<?php endif; ?>
<!-- K2 Plugins: K2AfterDisplay -->
<?php echo $item->event->K2AfterDisplay; ?>
<div class="clr"></div>
</li>
<?php if((($keyItem+1)%($params->get('num_columns'))==0) && (($placeholder != 'pagination'))) : ?>
<div class="clr"></div>
<?php endif; ?>
<?php endforeach; ?>
<li class="clearList"></li>
</ul>
<?php endif; ?>
<?php if($params->get('itemCustomLink')): ?>
<a class="moduleCustomLink" href="<?php echo $params->get('itemCustomLinkURL'); ?>" title="<?php echo K2HelperUtilities::cleanHtml($itemCustomLinkTitle); ?>"><?php echo $itemCustomLinkTitle; ?></a>
<?php endif; ?>
<?php if($params->get('feed')): ?>
<div class="k2FeedIcon">
<a href="<?php echo JRoute::_('index.php?option=com_k2&view=itemlist&format=feed&moduleID='.$module->id); ?>" title="<?php echo JText::_('K2_SUBSCRIBE_TO_THIS_RSS_FEED'); ?>">
<span><?php echo JText::_('K2_SUBSCRIBE_TO_THIS_RSS_FEED'); ?></span>
</a>
<div class="clr"></div>
</div>
<?php endif; ?>
</div>
Like I say, I've tried and tried to make this template work, but have got nowhere!
You try it with wrong file! This file belongs to Filtrify Module!
You must:
set as template for category "default"
edit K2 native category settings,
edit K2 native category item settings,
edit K2 native
item settings,
After you set all native K2 parameters, you must clone your default k2 template. Do it so:
go into components/com_k2/templates.
Copy all, what you see, locally.
Then create in you templates/your-template/html folder named com_k2.
Copy into it all, what you got befor from components/com_k2/templates.
Then duplicate folder named "default" and give them own name. This will be your K2 template for overrides.
Then go into K2 administration and change template of you category, which you set up befor, from default to the new name. Just now you can begin with template overrides, but ONLY inside of templates/your template/html/com_k2/your-k2-template. The files you need to override are category-item.php for category view and item.php for single item view.
I am getting the below error:
Parse error: syntax error,
unexpected $end in /var/www/html/joomla/components/com_jtagmembersdirectory/views/memberdetails/tmpl/default.php
on line 147
What could be the possible solution, I searched a number of posts, I do use <?php ?>
No opening and closing bracket issues and no quote issues.
Is there anything else which could cause this problem?
My code is like below,
<?php
defined('_JEXEC') or die('Restricted access');
$user =& JFactory::getUser();
$this->user_id = $user->id;
?>
<div class="Jtag_Members_Directory_details">
<h2 class="page-title"><?php echo JText:: _('JTAG_MEMBER_DETAIL');?></h2>
<div id="jtag-member-list">
<img width="225" src="components/com_jtagmembersdirectory/assets/profile_pictures/small/<?php echo $this->profile->profile_picture ? $this->profile->profile_picture : 'profile2.jpg' ?>" alt="" />
<div class="info details">
<?php if ($this->profile->user_id == $this->user_id && $this->profile->allow_edit):?>
<h2><?php echo $this->profile->name ?></h2>
<?php else:?>
<h2><?php echo $this->profile->name ?></h2>
<?php endif; ?>
<h4><?php echo JText:: _('JTAG_MEMBER_DETAIL_ABOUT_ME');?></h4>
<div><?php echo nl2br($this->profile->member_profile) ?></div>
<ul class="member-details">
<?php if($this->user_id !=0):?>
<?php if($this->profile->hasGallery==1 && $this->profile->display_gallery == 1):?>
<li><strong><?php echo JText:: _('JTAG_MEMBER_DETAIL_GALLERY');?></strong></li>
<?php endif;?>
<?php endif;?>
<?php if($this->user_id==0):?>
<?php if($this->profile->display_nr_country==1 && $this->profile->country):?>
<li><strong><?php echo JText:: _('JTAG_MEMBER_DETAIL_COUNTRY');?></strong> <?php echo $this->countries[$this->profile->country]; ?></li>
<?php endif;?>
<?php else:?>
<?php if( $this->profile->country):?>
<li><strong><?php echo JText:: _('JTAG_MEMBER_DETAIL_COUNTRY');?></strong> <?php echo $this->countries[$this->profile->country]; ?></li>
<?php endif;?>
<?php endif;?>
<?php if($this->user_id==0):?>
<?php if($this->profile->display_nr_city==1 && $this->profile->city):?>
<li><strong><?php echo JText:: _('JTAG_MEMBER_DETAIL_CITY');?></strong> <?php echo $this->profile->city; ?></li>
<?php endif;?>
<?php else:?>
<?php if( $this->profile->city && $this->profile->display_city):?>
<li><strong><?php echo JText:: _('JTAG_MEMBER_DETAIL_CITY');?></strong> <?php echo $this->profile->city; ?></li>
<?php endif;?>
<?php endif;?>
<?php if($this->user_id==0):?>
<?php if($this->profile->display_nr_state==1 && $this->profile->state):?>
<li><strong><?php echo JText:: _('JTAG_MEMBER_DETAIL_STATE');?></strong> <?php echo $this->profile->state; ?></li>
<?php endif;?>
<?php else:?>
<?php if( $this->profile->state ):?>
<li><strong><?php echo JText:: _('JTAG_MEMBER_DETAIL_STATE');?></strong> <?php echo $this->profile->state; ?></li>
<?php endif;?>
<?php endif;?>
<?php if($this->user_id==0):?>
<?php if($this->profile->display_nr_phone_no==1 && $this->profile->phone_no):?>
<li><strong><?php echo JText:: _('JTAG_MEMBER_DETAIL_PHONE_NO');?></strong> <?php echo $this->profile->phone_no ?></li>
<?php endif;?>
<?php else:?>
<?php if( $this->profile->phone_no && $this->profile->display_phone_no):?>
<li><strong><?php echo JText:: _('JTAG_MEMBER_DETAIL_PHONE_NO');?></strong> <?php echo $this->profile->phone_no ?></li>
<?php endif;?>
<?php endif;?>
<?php if($this->user_id==0):?>
<?php if($this->profile->display_nr_email==1 && $this->profile->Email):?>
<li><strong><?php echo JText:: _('JTAG_MEMBER_DETAIL_EMAIL');?></strong> <?php echo $this->profile->Email; ?></li>
<?php endif;?>
<?php else:?>
<?php if( $this->profile->Email):?>
<li><strong><?php echo JText:: _('JTAG_MEMBER_DETAIL_EMAIL');?></strong> <?php echo $this->profile->Email; ?></li>
<?php endif;?>
<?php endif;?>
<?php if($this->user_id==0):?>
<?php if($this->profile->display_nr_facebook==1 && $this->profile->facebook_page):?>
<li><strong><?php echo JText:: _('JTAG_MEMBER_DETAIL_FACEBOOK_PAGE');?></strong> <?php echo $this->profile->facebook_page ?></li>
<?php endif;?>
<?php else:?>
<?php if( $this->profile->facebook_page && $this->profile->display_facebook_page):?>
<li><strong><?php echo JText:: _('JTAG_MEMBER_DETAIL_FACEBOOK_PAGE');?></strong> <?php echo $this->profile->facebook_page ?></li>
<?php endif;?>
<?php endif;?>
<?php if($this->user_id==0):?>
<?php if($this->profile->display_nr_twitter==1 && $this->profile->twitter_page):?>
<li><strong><?php echo JText:: _('JTAG_MEMBER_DETAIL_TWITTER_PAGE');?></strong> <?php echo $this->profile->twitter_page ?></li>
<?php endif;?>
<?php else:?>
<?php if( $this->profile->twitter_page && $this->profile->display_twitter_page):?>
<li><strong><?php echo JText:: _('JTAG_MEMBER_DETAIL_TWITTER_PAGE');?></strong> <?php echo $this->profile->twitter_page ?></li>
<?php endif;?>
<?php endif;?>
<?php if($this->user_id):?>
<?php foreach ($this->profile->custom_fields as $field): ?>
<?php if ($field->field_label && $field->field_value): ?>
<li><strong><?php echo $field->field_label; ?>:</strong> <?php echo $field->field_value ?></li>
<?php endif; ?>
<?php endforeach; ?>
<?php else: ?>
<?php foreach ($this->profile->custom_fields as $field): ?>
<?php if ($field->field_label && $field->field_value && $field->display_nr_cf): ?>
<li><strong><?php echo $field->field_label; ?>:</strong> <?php echo $field->field_value ?></li>
<?php endif; ?>
<?php endforeach; ?>
<? endif;?>
</ul>
<?php echo JText:: _('BACK_TO_THE_LIST');?>
</div>
</div>
</div>
Unless you have short tags enabled, this line (#131) -
<? endif;?>
will not parse, ending your if
But you have also only posted 137 lines of code, and your code said it is on line #147, so there might be another issue.
First off I will say that I am new to Magento but not new to PHP. The question I have is why are there start and stop PHP calls for every line in the template files within Magento and is there a performance hit for doing so.
Here is an example:
<ul class="links<?php if($iecheckout):?> <?php echo $iecheckout ?><?php endif;?>"<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?>>
<?php foreach($_links as $_link): ?>
<?php if ($_link instanceof Mage_Core_Block_Abstract):?>
<?php echo $_link->toHtml() ?>
<?php else: ?>
<li<?php if($_link->getIsFirst()||$_link->getIsLast()): ?> class="<?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
<?php endif;?>
<?php endforeach; ?>
</ul>
so in this example, there are a lot of start and stops of the around sections that do not need to be broken up. for example with the last two lines, why call put the on each line? Is this apart to how the system reads these files? While I know it has to increase file space (all be it minimally but with 18k files it adds up), does it take PHP longer to interpret these files when you are starting the PHP tags and stopping them over and over again. Magento is a huge system and I am sure any performance increase could be helpful.
would it not make more sense to have the block
<?php foreach($_links as $_link): ?>
<?php if ($_link instanceof Mage_Core_Block_Abstract):?>
<?php echo $_link->toHtml() ?>
<?php else: ?>
<li<?php if($_link->getIsFirst()||$_link->getIsLast()): ?> class="<?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
<?php endif;?>
<?php endforeach; ?>
look like
<?php
foreach($_links as $_link):
if ($_link instanceof Mage_Core_Block_Abstract):
echo $_link->toHtml()
else:
?>
<li<?php if($_link->getIsFirst()||$_link->getIsLast()): ?> class="<?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
<?php
endif;
endforeach; ?>
Does this make sense? Is this just to mimic some HTML type layout? As I get more used to this system, should I be writing templates in this manor even though it looks like it is harder to read?
Thanks for any information anyone can give.
The reason I use the following in templates (not the controllers, models, etc):
<?php if ($condition): ?>
<?php foreach($items as $item): ?>
<?php endforeach ?>
<?php endif ?>
Instead of:
<?php if ($condition):
foreach($items as $item): ?>
<?php endforeach;
endif; ?>
Is purely for readability.
As for performance impact from opening and close tags goes, which appears to be what your question boils down to, you might want to checkout Opening/closing tags & performance?.