Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Setting carousel href with smarty.
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
anything7pob
Smarty Rookie


Joined: 26 Mar 2017
Posts: 26

PostPosted: Wed Mar 29, 2017 8:12 pm    Post subject: Setting carousel href with smarty. Reply with quote

Code:
{counter start=1 skip=1 print=false assign=x}
  {foreach from=$carouselArray key=$a item=$b}
   {if $b@first}
    [color=orange]<li data-target="#{$carouselArray.$x.title}"[/color] data-slide-to="0" class="active"></li>
   {else}
    <li data-target="#{$carouselArray.$x.title}" data-slide-to="$counter"></li>
   {/if}
   {/foreach}
  </ol>


I can`t get the <li data-target="#{$carouselArray.$x.title}" to work, is displaying as a webpage and trying to link me via my carousel buttons. Seems to be ignoring the#.... Mad


Last edited by anything7pob on Fri Mar 31, 2017 11:49 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
anything7pob
Smarty Rookie


Joined: 26 Mar 2017
Posts: 26

PostPosted: Wed Mar 29, 2017 8:35 pm    Post subject: Reply with quote

ok, I gave up. I`ll add a column in the DB for the full href including the #.
Back to top
View user's profile Send private message Send e-mail
anything7pob
Smarty Rookie


Joined: 26 Mar 2017
Posts: 26

PostPosted: Wed Mar 29, 2017 8:42 pm    Post subject: Reply with quote

Ballz that didn`t work either...
Back to top
View user's profile Send private message Send e-mail
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Thu Mar 30, 2017 12:26 am    Post subject: Reply with quote

Did you try to compare the resulting page code with your expected results?
Back to top
View user's profile Send private message
anything7pob
Smarty Rookie


Joined: 26 Mar 2017
Posts: 26

PostPosted: Thu Mar 30, 2017 1:48 pm    Post subject: Reply with quote

Hi and thank you for your reply.

I am just getting to grips with my dev environment (new word for me, seems to fit..) as you seem to have guessed.

It was worrying me that the carousel buttons when hovered showed a long file path before the expected "#myCarousel" but that turned out to be normal behaviour that I just didn`t recognise.

It seems that my problem was actually stating carousel ID=#myCarousel
when the # is only needed on the slides Embarassed

I`m here now:
(everything is working but my second carousel still shows first set of images, (see ineffectiuve multiple smarty counters setup.)

$x this value is not increasing with each (percieved by me) iteration This is the variable that should specify a new image array instead of reusing the first.

$y this value is not increasing with each (percieved by me) iteration A ll of the "data-slide-to=" display a value of 1 although the previous/next buttons still seem to work.

When does counter iterate? with every insertion (doesn`t seem so from my results). So I guess it is attached to the for each loop?

I am guessing/hoping that my foreach loops are interfering and my setup is a little out or maybe I need to research "smarty sections" as I am using more than one array.

Maybe there is a simpler way. I have added the images to the tileArray so I could maybe get rid of the iterations and use smarty if functions:

Code:
{if tileArray.{$x}.carouselIMG1 =!NULL} but it still uses a counter.... I think,... my brain hurts.


[color=red]{counter start=0 skip=1 print=false assign=x}[/color]
[color=orange]{counter start=1 skip=1 print=false assign=y}[/color]
{counter start=0 skip=1 print=false assign=z}

{foreach from=$tileArray key=k item=v}
<div id="tilegrid" class="flex-container">

    <div class="flex-item">


         <h3 class="redbacktitle">{$v.1}</h3><p>{$v.2}</p>
<p><span class="red">&gt; </span>{$v.3}</p>
<p><span class="red">&gt; </span>{$v.4}</p>
<p><span class="red">&gt; </span>{$v.5}</p>
<p><span class="red">&gt; </span>{$v.6}</p>

   </div>

   <div class="flex-item">
   <div id="{$v.carouselTitle}" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">

  {foreach from=$carouselArray{$z} key=$a item=$b}
 
 
   {if $b@first}
    <li data-target="#{$v.carouselTitle}" data-slide-to="0" class="active"></li>
   {else}
   
    <li data-target="#{$v.carouselTitle}" data-slide-to="[color=orange]{$y}[/color]"></li>
   {/if}
   {/foreach}
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
  {foreach from=$carouselArray[color=[color=red]{$x}[/color] key=$c item=$d}
 {if $d@first}
 <div class="item active">
      <img src="{$d.4}">
      <div class="carousel-caption">
        <h3>{$d.2}</h3>
        <p>{$d.3}</p>
      </div>
    </div>
   
{else}   
    <div class="item">
      <img src="{$d.4}">
      <div class="carousel-caption">
        <h3>{$d.2}</h3>
        <p>{$d.3}</p>
      </div>
    </div>
   {/if}
{/foreach}
   
   
  </div>

  <!-- Left and right controls -->
  <a class="left carousel-control" href="#{$v.carouselTitle}" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#{$v.carouselTitle}" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>
   </div>
   
   <div class="flex-item" style="text-align:center;">
   
   <div class="left">
   <p style="text-align: left;">Average Terraced</p>
    <p style="text-align: left;">Average Semi</p>
    <p style="text-align: left;">Average Detached</p>
   </div>
   
   <div class="right">
   <p style="text-align: center;">£{$v.28}</p>
    <p style="text-align: center;">£{$v.29}</p>
    <p style="text-align: center;">£{$v.30}</p>
   </div>
   
   <img src="{$v.31}" />
   
    </div>
   </div>
   
{/foreach}


Last edited by anything7pob on Fri Mar 31, 2017 11:51 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
anything7pob
Smarty Rookie


Joined: 26 Mar 2017
Posts: 26

PostPosted: Thu Mar 30, 2017 2:19 pm    Post subject: Reply with quote

Ahh, it seems to me that my problem was that I had nested a foreach loop within another foreach loop.

I believe that this is not possible and I instead need to use sections...
Back to top
View user's profile Send private message Send e-mail
anything7pob
Smarty Rookie


Joined: 26 Mar 2017
Posts: 26

PostPosted: Thu Mar 30, 2017 4:04 pm    Post subject: Reply with quote

This is the code now. I swapped out the foreach for sections.
At first I had no foreach loops just nested sections, but @first didnt work on the section so I added a for each loop and now it is broken again...

notice: Undefined index: carouselArray in C:\wamp\www\smartyrooftiler\public_html\Smarty\templates_c\d7f5eb924373d603b12b1bceb7ede7d6d583150c_0.file.layout.tpl.php on line 926


Code:
{section name=tileDisplay loop=$tileArray}


<div id="tilegrid" class="flex-container">

    <div class="flex-item">


         <h3 class="redbacktitle">{$tileArray[tileDisplay].1}</h3><p>{$tileArray[tileDisplay].2}</p>
<p><span class="red">&gt; </span>{$tileArray[tileDisplay].3}</p>
<p><span class="red">&gt; </span>{$tileArray[tileDisplay].4}</p>
<p><span class="red">&gt; </span>{$tileArray[tileDisplay].5}</p>
<p><span class="red">&gt; </span>{$tileArray[tileDisplay].6}</p>

   </div>

   <div class="flex-item">
   <div id="{$tileArray[tileDisplay].carouselTitle}" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">

{counter start=0 skip=1 print=false assign=z}
 {foreach from=$carouselArray[tileDisplay] key=$a item=$b}
[color=green] //foreach nested in section[/color]
   
 
    <li data-target="#{$tileArray[tileDisplay].carouselTitle}" data-slide-to="{$z}"
   {if $b@first} 
    class="active"></li>
   {else}
    ></li>
   {/if}
   {/foreach}
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
{foreach from=$carouselArray[tileDisplay] key=$a item=$b}
 <div class="item
 {if $b@first}
  active">
 {else}
">
   {/if}
{/foreach}   
  </div>

  <!-- Left and right controls -->
  <a class="left carousel-control" href="#{$carouselArray[tileDisplay].carouselTitle}" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#{$carouselArray[tileDisplay].carouselTitle}" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>
   </div>
   
   <div class="flex-item" style="text-align:center;">
   
   <div class="left">
   <p style="text-align: left;">Average Terraced</p>
    <p style="text-align: left;">Average Semi</p>
    <p style="text-align: left;">Average Detached</p>
   </div>
   
   <div class="right">
   <p style="text-align: center;">£{$carouselArray[tileDisplay].terracedPrice}</p>
    <p style="text-align: center;">£{$carouselArray[tileDisplay].semiPrice}</p>
    <p style="text-align: center;">£{$carouselArray[tileDisplay].detachedPrice}</p>
   </div>
   
   <img src="{$carouselArray[tileDisplay].tilePromoIMG}" />
   
    </div>
   </div>

{/section}


I am guessing that I cannot nest a foreach in a section, I am going to revert to all sections and try to use iteration or another function instead of at @first......


Last edited by anything7pob on Fri Mar 31, 2017 11:52 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
anything7pob
Smarty Rookie


Joined: 26 Mar 2017
Posts: 26

PostPosted: Thu Mar 30, 2017 4:55 pm    Post subject: Reply with quote

I swapped out all of the foreach loops for section loops and attempted to utilise .index as a replacement for @first.

Code:
{section name=tileDisplay loop=$tileArray}


<div id="tilegrid" class="flex-container">

    <div class="flex-item">


         <h3 class="redbacktitle">{$tileArray[tileDisplay].1}</h3><p>{$tileArray[tileDisplay].2}</p>
<p><span class="red">&gt; </span>{$tileArray[tileDisplay].3}</p>
<p><span class="red">&gt; </span>{$tileArray[tileDisplay].4}</p>
<p><span class="red">&gt; </span>{$tileArray[tileDisplay].5}</p>
<p><span class="red">&gt; </span>{$tileArray[tileDisplay].6}</p>

   </div>

   <div class="flex-item">
   <div id="{$tileArray[tileDisplay].carouselTitle}" class="carousel slide" data-ride="carousel">
  <!-- Indicators -->
  <ol class="carousel-indicators">

  {section name=IMGDisplay loop=$carouselArray[color=red][tileDisplay][/color]}[color=green] // is it the section variable within the section smarty tag causing an issue maybe?[/color]
   
    <li data-target="#{$tileArray[tileDisplay].carouselTitle}" data-slide-to="[IMGDisplay]"
   {if $smarty.section.IMGDisplay[color=violet].index[/color] = "0"}
   class="active"></li>
   {else}
   ></li>
   {/if} 
   {/section}
  </ol>

  <!-- Wrapper for slides -->
  <div class="carousel-inner" role="listbox">
  {section name=IMGDisplay2 loop=$carouselArray[tileDisplay]}
 
 <div class="item
 {if $smarty.section.IMGDisplay2.index = "0"}
 active">
 {else}
 ">
 {/if}
      <img src="{$carouselArray[tileDisplay].4}">
      <div class="carousel-caption">
        <h3>{$carouselArray[tileDisplay].2}</h3>
        <p>{$carouselArray[tileDisplay].3}</p>
      </div>
    </div>
   

{/section}
   
   
  </div>

  <!-- Left and right controls -->
  <a class="left carousel-control" href="#{$carouselArray[tileDisplay].carouselTitle}" role="button" data-slide="prev">
    <span class="glyphicon glyphicon-chevron-left" aria-hidden="true"></span>
    <span class="sr-only">Previous</span>
  </a>
  <a class="right carousel-control" href="#{$carouselArray[tileDisplay].carouselTitle}" role="button" data-slide="next">
    <span class="glyphicon glyphicon-chevron-right" aria-hidden="true"></span>
    <span class="sr-only">Next</span>
  </a>
</div>
   </div>
   
   <div class="flex-item" style="text-align:center;">
   
   <div class="left">
   <p style="text-align: left;">Average Terraced</p>
    <p style="text-align: left;">Average Semi</p>
    <p style="text-align: left;">Average Detached</p>
   </div>
   
   <div class="right">
   <p style="text-align: center;">£{$carouselArray[tileDisplay].28}</p>
    <p style="text-align: center;">£{$carouselArray[tileDisplay].29}</p>
    <p style="text-align: center;">£{$carouselArray[tileDisplay].30}</p>
   </div>
   
   <img src="{$carouselArray[tileDisplay].31}" />
   
    </div>
   </div>

{/section}


notice: Undefined index: [color=blue]carouselArray in C:\wamp\www\smartyrooftiler\public_html\Smarty\templates_c\d7f5eb924373d603b12b1bceb7ede7d6d583150c_0.file.layout.tpl.php on line 946[/color]

I am getting the same error response.
It is on a weird smarty template page and the line numbers seems to be off.
carouselArray only exists as carouselArray0 and carouselArray1 in my pages, or so I thought.

I`m not sure what my problem is here???

It actually seems like my page has run through without error and only now uncovered a pre existing array problem.

I have a feeling my php is not setting the variables

Code:
$stmt = $reg_user->runQuery("SELECT * FROM Tile ");
 $stmt->execute (array());
 $tileArray = $stmt->fetchall();
for ([color=orange]$x = 0; $x <= count($tileArray); $x++[/color]){
if (array_key_exists($x,$tileArray)){
$ownerTitle=$tileArray[$x][1];
${'carouselArray'.$x} = $reg_user->carouselSelect($ownerTitle);
var_dump(${'carouselArray'.$x});
}
}

var dump works as expected

Code:
$smarty->assign('carouselArray0', $carouselArray0);
$smarty->assign('carouselArray1', $carouselArray1);

nothing fancy here..


Last edited by anything7pob on Fri Mar 31, 2017 11:54 am; edited 3 times in total
Back to top
View user's profile Send private message Send e-mail
anything7pob
Smarty Rookie


Joined: 26 Mar 2017
Posts: 26

PostPosted: Thu Mar 30, 2017 5:25 pm    Post subject: Reply with quote

It my counting function!!! I think...
Back to top
View user's profile Send private message Send e-mail
anything7pob
Smarty Rookie


Joined: 26 Mar 2017
Posts: 26

PostPosted: Thu Mar 30, 2017 7:46 pm    Post subject: Reply with quote

Nope, or the var_dump wouldn`t work..

Code:
{$carouselArray[tileDisplay].terracedPrice}


I need this to display as "$carouselArray0[terracedPrice]"
not "$carouselArray[0][terracedPrice]"...

need to swap [tileDisplay] out


Last edited by anything7pob on Fri Mar 31, 2017 11:54 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
anything7pob
Smarty Rookie


Joined: 26 Mar 2017
Posts: 26

PostPosted: Thu Mar 30, 2017 11:19 pm    Post subject: Reply with quote

Still haven`t managed to get it to work.

Code:
for ($x = 0, $count=count($tileArray);$x<$count;$x++){
if (array_key_exists($x,$tileArray)){
$ownerTitle=$tileArray[$x][1];
$carouselTitle=$tileArray[$x][9];
$tempArray = $reg_user->carouselSelect($ownerTitle);
var_dump($tempArray);
$smarty->assign($carouselArray['assign'],$tempArray);
}
}

I am trying to set each iteration as an array within $carouselArray at the minute.

I am getting no errors but the array seems to be empty as it returns no img`s.

Code:
{section name=carouselDisplay loop=$carouselArray[tileDisplay] start=0 step=1}

Can I use [tileDisplay] within the section tag (it is the iteration variable of a previous section?


Last edited by anything7pob on Fri Mar 31, 2017 11:55 am; edited 2 times in total
Back to top
View user's profile Send private message Send e-mail
anything7pob
Smarty Rookie


Joined: 26 Mar 2017
Posts: 26

PostPosted: Fri Mar 31, 2017 1:28 am    Post subject: Reply with quote

Tomorrow start with a fresh slate now I understand a bit better.
Back to top
View user's profile Send private message Send e-mail
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Mar 31, 2017 2:26 am    Post subject: Reply with quote

{foreach} loops can be nested, of course.
{section} is still a foreach() loop.
{counter} increments when used, unless you specifically tell it to not do that.
Please use [ code ] tags for your code, your posts are unreadable.
Back to top
View user's profile Send private message
anything7pob
Smarty Rookie


Joined: 26 Mar 2017
Posts: 26

PostPosted: Fri Mar 31, 2017 11:49 am    Post subject: Reply with quote

AnrDaemon wrote:
{foreach} loops can be nested, of course.
{section} is still a foreach() loop.
{counter} increments when used, unless you specifically tell it to not do that.
Please use [ code ] tags for your code, your posts are unreadable.


Thank you again for your input.

Sorry about my posts, noob error, I will cetainly make sure to use the code tag in the future.

As far as my code, I feel I am overcomplicating it by trying to do too much with smarty and then wasting hours trying to force my inefficient code to work.

Think I need to sit down and design properly, I know now what I need from php, need to send the data in the form that is easiest to use in a .tpl.

Should be a single array for each loop in the display (array[0]) containing the code for the first loop, (array[1]) the second (array[2]) the third.

I would like to then compile all of these arrays into a single array that is assigned to scrapy.

Then I will only need one loop in smarty instead of three which is what seems to be causing me problems with my limited smarty knowledge.


Last edited by anything7pob on Fri Mar 31, 2017 10:28 pm; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
AnrDaemon
Administrator


Joined: 03 Dec 2012
Posts: 1785

PostPosted: Fri Mar 31, 2017 3:55 pm    Post subject: Reply with quote

Depends how your backend is set up, you could either prepare an array before sending it to Smarty, or use raw arrays to loop over, if it's one-to-many relation.
In either case, what you need to understand is that the result of your PHP/Smarty work is plain HTML that is sent to the client AFTER your PHP/Smarty code is finished, but BEFORE anything happens on client (i.e. Carousel takes any note of the changes).
That's why I told you to look directly at the code rendered by your template, don't trust your browser tooltips.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP