Open Abhinav1217 opened 9 years ago
The easiest way to debug this, is to open the compiled template and check how that got compiled, in base of that you can change the code into your template.
I think you only need to get the right folder, that's all.
Please, let me know if that helps.
On Sun, Sep 6, 2015 at 12:30 AM, Abhinav Kulshreshtha < notifications@github.com> wrote:
I was refactoring an old application when I got stuck in a situation. When I {include="CouponSection"} and CouponSection in on the same path. Everything works fine.
But when "CouponSection" is in a subdirectory, {include="Modules/CouponSection"} Plain HTML in included but none of the {} is parsed. No data is filled, No conditions were working. Strangely loop does execute if it in the included file, But Including a file within a loop does not work.
{loop="$coupons"} {include="Modules/CouponSection"} {/loop}Above doesnot work.
{include="Modules/CouponSection"}Above does work if I add {loop="$coupons"} .... {/loop} in the Modules/CouponSection Itself. But that would make it non-resuable.
What am I doing wrong.
— Reply to this email directly or view it on GitHub https://github.com/rainphp/raintpl/issues/51.
This is output when {loop}
is in the page which includes the couponsection module. No Coupon is visible at this point. Also, I noticed after your suggestion, Anything below the include statement is also not rendered on the screen. I didn't notice before because I was loading only central section of the page. Not the header or footer. I created a separate test project and then it came to notice that footer was missing.
ShowCoupons.tpl
<div class="wrapper">
<div class="coupon-wrapper">
{if="$is_empty==false"}
<h1> Search Results </h1>
{loop="$Coupons"}
{include="Modules/CouponSection"}
{/loop}
{else}
<h1> No Results Found </h1>
{/if}
</div>
</div>
ShowCoupons.{hash}.rtpl.php
<h1> Search Results </h1>
<?php $counter1=-1; if( isset($coupons) && ( is_array($coupons) || $coupons instanceof Traversable ) && sizeof($coupons) ) foreach( $coupons as $key1 => $value1 ){ $counter1++; ?>
<?php require $this->checkTemplate("Modules/CouponSection");?>
<?php } ?>
CouponSection.{hash}.rtpl.php
<?php if(!class_exists('Rain\Tpl')){exit;}?>
<div id="couponID-<?php echo htmlspecialchars( $value["id"], ENT_COMPAT, 'UTF-8', FALSE ); ?>" class="coupon-container" vendor-id="">
<div class="image-vendor">
<img src="<?php echo htmlspecialchars( $storeImagesPath, ENT_COMPAT, 'UTF-8', FALSE ); ?>/logo-<?php echo htmlspecialchars( $value["StoreID"], ENT_COMPAT, 'UTF-8', FALSE ); ?>.png" alt="<?php echo htmlspecialchars( $value["StoreName"], ENT_COMPAT, 'UTF-8', FALSE ); ?>" class="coupan-banner" />
</div>
<div class="inner-wrapper">
<div class="title-vendor">
<h3><?php echo htmlspecialchars( $value["StoreName"], ENT_COMPAT, 'UTF-8', FALSE ); ?></h3>
</div>
<div class="title-offer">
<p class="short-description"><?php echo htmlspecialchars( $value["Title"], ENT_COMPAT, 'UTF-8', FALSE ); ?></p>
</div>
<div class="offer-deal">
<div id="<?php echo htmlspecialchars( $value["id"], ENT_COMPAT, 'UTF-8', FALSE ); ?>" class="button button-deal coupon-click" data-type="online" data-couponid="<?php echo htmlspecialchars( $value["id"], ENT_COMPAT, 'UTF-8', FALSE ); ?>" data-coupontype="Deal" data-clickarea="HomeButton" data-websitename="<?php echo htmlspecialchars( $value["StoreName"], ENT_COMPAT, 'UTF-8', FALSE ); ?>" data-url="/Deal/<?php echo htmlspecialchars( $value["id"], ENT_COMPAT, 'UTF-8', FALSE ); ?>">Activate DEAL</div>
</div>
<a href="/Store/<?php echo htmlspecialchars( $value["StoreName"], ENT_COMPAT, 'UTF-8', FALSE ); ?>/<?php echo htmlspecialchars( $value["StoreID"], ENT_COMPAT, 'UTF-8', FALSE ); ?>" class="read-more">SEE ALL <?php echo htmlspecialchars( $value["StoreName"], ENT_COMPAT, 'UTF-8', FALSE ); ?> OFFERS</a>
</div>
</div>
When I move the {loop}
portion from ShowCoupons.tpl
to Modules/CouponSection.tpl
Everything works fine
CouponSection.{hash}.rtpl.php
<?php if(!class_exists('Rain\Tpl')){exit;}?><?php $counter1=-1; if( isset($Coupons) && ( is_array($Coupons) || $Coupons instanceof Traversable ) && sizeof($Coupons) ) foreach( $Coupons as $key1 => $value1 ){ $counter1++; ?>
<div id="couponID-<?php echo htmlspecialchars( $value1["id"], ENT_COMPAT, 'UTF-8', FALSE ); ?>" class="coupon-container" vendor-id="">
<div class="image-vendor">
<img src="<?php echo htmlspecialchars( $storeImagesPath, ENT_COMPAT, 'UTF-8', FALSE ); ?>/logo-<?php echo htmlspecialchars( $value1["StoreID"], ENT_COMPAT, 'UTF-8', FALSE ); ?>.png" alt="<?php echo htmlspecialchars( $value1["StoreName"], ENT_COMPAT, 'UTF-8', FALSE ); ?>" class="coupan-banner" />
</div>
<div class="inner-wrapper">
<div class="title-vendor">
<h3><?php echo htmlspecialchars( $value1["StoreName"], ENT_COMPAT, 'UTF-8', FALSE ); ?></h3>
</div>
<div class="title-offer">
<p class="short-description"><?php echo htmlspecialchars( $value1["Title"], ENT_COMPAT, 'UTF-8', FALSE ); ?></p>
</div>
<div class="offer-deal">
<div id="<?php echo htmlspecialchars( $value1["id"], ENT_COMPAT, 'UTF-8', FALSE ); ?>" class="button button-deal coupon-click" data-type="online" data-couponid="<?php echo htmlspecialchars( $value1["id"], ENT_COMPAT, 'UTF-8', FALSE ); ?>" data-coupontype="Deal" data-clickarea="HomeButton" data-websitename="<?php echo htmlspecialchars( $value1["StoreName"], ENT_COMPAT, 'UTF-8', FALSE ); ?>" data-url="/Deal/<?php echo htmlspecialchars( $value1["id"], ENT_COMPAT, 'UTF-8', FALSE ); ?>">Activate DEAL</div>
</div>
<a href="/Store/<?php echo htmlspecialchars( $value1["StoreName"], ENT_COMPAT, 'UTF-8', FALSE ); ?>/<?php echo htmlspecialchars( $value1["StoreID"], ENT_COMPAT, 'UTF-8', FALSE ); ?>" class="read-more">SEE ALL <?php echo htmlspecialchars( $value1["StoreName"], ENT_COMPAT, 'UTF-8', FALSE ); ?> OFFERS</a>
</div>
</div>
<?php } ?>
I Cant pin point the cause. I experimented with it a lot. Any further suggestion. I currently have to 8 same couponsection
with different array variable name because of this. And I haven't even started with responsive templates.
I was refactoring an old application when I got stuck in a situation. When I
{include="CouponSection"}
andCouponSection
in on the same path. Everything works fine.But when "CouponSection" is in a subdirectory,
{include="Modules/CouponSection"}
Plain HTML is included but none of the{}
is filled with data, No conditions were working. Strangelyloop
does execute if it in the included file, But Including a file within a loop does not work.For Example -
Above does not work.
Above does work if I add
{loop="$coupons"} .... {/loop}
in theModules/CouponSection
Itself. But that would make it non-resuable.What am I doing wrong.