Inserting php into my album.tpl - Its breaking my template.
nonamer69
Joined: 2005-09-09
Posts: 21 |
![]() |
I'm trying to include this php code into my site. while understanding how the smarty engine works I've changed the code to the below. {php} $start = "June 6, 2007"; $now = strtotime ("now"); $then = strtotime ("$start"); $difference = $now - $then ; $num = $difference/86400; $num1 = $num/7; $weeks = intval($num1); $num1a = $difference/86400 - $weeks*7; $days = intval($num1a); $num2 = ($difference/86400 - intval($difference/86400))*24; $hours = intval($num2); $num3 = ($num2 - $hours)*60; $mins = intval($num3); $num4 = ($num3 - $mins)*60; $secs = intval($num4); ?> <p> <? echo $weeks ?> weeks, <? echo $days ?> days. </p> {/php} the end result causes some kind of issue with the echo tags. When this php code is inserted it results in killing my customfields. If I remove the above code my template looks just fine and the customfields work again. Any suggestions because I'm new to the smarty crap. its a work in progress and I need your help. here yah go... all help is appreciated, |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
{php} $start = "June 6, 2007"; $now = strtotime ("now"); $then = strtotime ("$start"); $difference = $now - $then ; $num = $difference/86400; $num1 = $num/7; $weeks = intval($num1); $num1a = $difference/86400 - $weeks*7; $days = intval($num1a); $num2 = ($difference/86400 - intval($difference/86400))*24; $hours = intval($num2); $num3 = ($num2 - $hours)*60; $mins = intval($num3); $num4 = ($num3 - $mins)*60; $secs = intval($num4); {/php} <p> {php} echo $weeks {/php} weeks, {php} echo $days {/php} days. </p> I bet there is a way to do all that with a build in smarty function. |
|
nonamer69
Joined: 2005-09-09
Posts: 21 |
![]() |
unfortunately that code didn't work. I was over at phpinsider earlier trying to search down the echo tags in smarty but I'm really thrown for a loop on what to ask or to even what to search over there. I'm not familiar at all with what you mean a build in smarty function. thanks dave for your help. |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Try: {php} $start = "June 6, 2007"; $now = strtotime ("now"); $then = strtotime ("$start"); $difference = $now - $then ; $num = $difference/86400; $num1 = $num/7; $weeks = intval($num1); $num1a = $difference/86400 - $weeks*7; $days = intval($num1a); $num2 = ($difference/86400 - intval($difference/86400))*24; $hours = intval($num2); $num3 = ($num2 - $hours)*60; $mins = intval($num3); $num4 = ($num3 - $mins)*60; $secs = intval($num4); echo $weeks; echo "weeks "; echo $days; echo " days"; {/php}
Looks funny so you might have to do some spaces and it still says days if the value is one day. Dave |
|
nonamer69
Joined: 2005-09-09
Posts: 21 |
![]() |
that worked great Dave until I placed a customfield for the $start. Would you happen to know how I could insert a customfield within php tags because now when I replace the date with a custom field it won't accept it. see below. {php} $start = "{$block.customfield.LoadCustomFields.fields.born}"; $now = strtotime ("now"); $then = strtotime ("$start"); $difference = $now - $then ; $num = $difference/86400; $num1 = $num/7; $weeks = intval($num1); $num1a = $difference/86400 - $weeks*7; $days = intval($num1a); $num2 = ($difference/86400 - intval($difference/86400))*24; $hours = intval($num2); $num3 = ($num2 - $hours)*60; $mins = intval($num3); $num4 = ($num3 - $mins)*60; $secs = intval($num4); echo $weeks; echo " weeks "; echo $days; echo ", days"; {/php} thanks Dave for all your help. it means so much. |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
When you add I tried somthing like: {assign var='name' value='June 16, 2005'} {php} $start = $name; .... .... .... and it seems to work. Dave |
|
nonamer69
Joined: 2005-09-09
Posts: 21 |
![]() |
it breaks the whole page and doesn't generate the albums at all when I just simply insert the customfield inside the php tags. I tried every combination to make that sample code you posted work but appears the customfield is not penetrating the php tags. any other suggestions? |
|
nonamer69
Joined: 2005-09-09
Posts: 21 |
![]() |
Okay, to anyone who can either build a gallery module to do what I need or make this php script work with custom fields I will paypal them $100 buckaroos. Please anyone. |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
save this: <?php /** * Smarty plugin * @package Smarty * @subpackage plugins */ /** * Smarty strip modifier plugin * * Type: modifier * Name: date_lapse * Purpose: Replace date with the difference between now * and the date * Example: {$date|date_lapse} * Date: July 23th, 2007 * @author floridave * @version 1.0 * @param string * @param string * @return string */ function smarty_modifier_date_lapse($date) { $now = strtotime ("now"); $then = strtotime ("$date"); $difference = $now - $then ; $num = $difference/86400; $num1 = $num/7; $weeks = intval($num1); $num1a = $difference/86400 - $weeks*7; $days = intval($num1a); $num2 = ($difference/86400 - intval($difference/86400))*24; $hours = intval($num2); $num3 = ($num2 - $hours)*60; $mins = intval($num3); $num4 = ($num3 - $mins)*60; $secs = intval($num4); $date_lapse = $weeks . 'weeks ' . $days . 'days '; return $date_lapse; } ?> As gallery2/lib/smarty/plugins/modifier.date_lapse.php Then you can use it like: Dave |
|
nonamer69
Joined: 2005-09-09
Posts: 21 |
![]() |
still getting 0 weeks 0 days? Is it possible I need extra quotations somewhere in that code because the start date does carry quotations in the original php script? |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
In album.tpl I have {g->callback type="customfield.LoadCustomFields" itemId=$theme.item.id} Original date: {$block.customfield.LoadCustomFields.fields.born} :<br> Lapsed time: {$block.customfield.LoadCustomFields.fields.born|date_lapse} I set a custom field for the album as: works on my test album: perhaps you di not load the custom fields to the template? Dave _____________________________________________ |
|
nonamer69
Joined: 2005-09-09
Posts: 21 |
![]() |
it does work on photos within albums but doesn't work for the main albums. any fix for that and whats your paypal address by the way. :D [url]LINK REMOVED[/url] thanks, |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Quote:
it does work on photos within albums but doesn't work for the main albums Then you have to add a custom field to the album as well as the photo. It would be good the wrap it all in a Dave _____________________________________________ |
|
nonamer69
Joined: 2005-09-09
Posts: 21 |
![]() |
the born field is in the album fields. You can see it listed down the list of that album on my page but its not generating the script. |
|
nonamer69
Joined: 2005-09-09
Posts: 21 |
![]() |
I figured it out. had to change itemId=$theme.item.id to itemId=$child.id and now it works. thanks Dave for your help. |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Glad you got it sorted. Dave |
|
nonamer
Joined: 2007-03-28
Posts: 63 |
![]() |
Hi floridave. could you help me with another script? I want to do really the same thing with this one making it a modifier named modifier.add_weeks.php to call from a customfield. I tried to read between the lines of what you did to convert the script above but I'm just not getting anywhere doing this one myself I need this script to work with the date format of "F j, Y" calling from a customfield. Also need it to use weeks instead of months to generate the future date. I'll even dish out $50 bucks to whoever can help me get it going. Quote:
<?php You've been such a great help. thanks again, EDIT:I MADE AN ERROR IN POSTING THE SCRIPT. |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Have you tested the above code by itself with values you will give it? Dave _____________________________________________ |
|
nonamer
Joined: 2007-03-28
Posts: 63 |
![]() |
Hey Dave, I just figured it out. I found another script and following along the lines of what you did in the date_lapse modifier I was able to get it. Thanks for getting back with me. This probably won't be the last time you hear from me ;) |
|
floridave
![]()
Joined: 2003-12-22
Posts: 27300 |
![]() |
Glad you sorted it out. Please post your results for others to benefit. Dave |
|
nonamer
Joined: 2007-03-28
Posts: 63 |
![]() |
okay, here it is. create php file named: modifier.add_lapse.php <?php /** * Smarty plugin * @package Smarty * @subpackage plugins */ /** * Smarty strip modifier plugin * * Type: modifier * Name: add_lapse * Purpose: Generates Future Date using the format "January 1, 2007". * Example: {$date|add_lapse} Adds 56 days (8weeks) to date. * Date: December 11th, 2007 * @author nonamer66 * @version 1.0 * @param string * @param string * @return string */ function smarty_modifier_add_lapse($adding) { $ts = getdate(strtotime("$adding")); $newTs = mktime(0, 0, 0, $ts["mon"], $ts["mday"] + 56, $ts["year"]); $add_lapse = date("F j, Y", $newTs); return $add_lapse; } ?>
example use... |
|
LionUk
Joined: 2008-04-02
Posts: 1 |
![]() |
HELP! like my age is "days" old i try hard find about remove weeks and just in days try fix smarty scripts, and find scripts for me just days thank cheerio NOTE cheerio |
|
spex
Joined: 2008-05-26
Posts: 1 |
![]() |
Welcome I need help with small modifications to the template siriux. I need to add For example, I have such directories: I can prepare this: Quote:
Bus However, I need to do is this: I thought that used to empty the folder with a special name. If the name of the directory will be normal or "Bus2" is the script will go normally. But if it is "___Bus" will be replaced by a decimal point. Disinterested code checking the names of the categories. Unfortunately, it can not implement the skin. I need help with that. Quote:
<?php Maybe you know a better solution? |
|