Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

smarty + php - Conditional page break ...

Status
Not open for further replies.

southbeach

Programmer
Jan 22, 2008
879
US
Hope this is the correct forum for this question ...

Using smarty template engine, I am trying to conditionally add a page break
Code:
				{assign var="left_line_count" value="`$left_line_count`+1" }
				{ if $left_line_count > $max_lines_page }
					<p class="break">Page Break!</p>
					{assign var="left_line_count" value="18" }
				{ /if }
This snippet appears under each row tab
Code:
<tr> blah blah blah </tr>

The CSS I am using is
Code:
p.break { page-break-after: always; }

I do not see the string "Page Break" on the rendered page nor I get a page break if I print the document. This tells me that there is something wrong with my logic and/or syntax.

Can you offer some advise?

Thanks!


--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
i am not familiar with the smarty language constructs. i thought it was based on php but seeing your script i am not confident that this is right. php knows nothing, for example, of constructs like assign. and if conditionals must be encapsulated in brackets.

but going back to first principles, there is nothing intrinsically wrong with your html and css. the css may be disapplied due to more granular rules being applied but more likely is that your conditional is not being fired. does the code work if you remove the conditional?

and does this work?

Code:
value="`$left_line_count`+1"
would this not simply assign the value "5+1" in each case? i.e. the string form. not knowing smarty i am not sure. perhaps this would work

Code:
{assign var="left_line_count" value=$left_line_count+1}
{ if $left_line_count > $max_lines_page }
<p class="break">Page Break!</p>
{assign var="left_line_count" value="18" }
{ /if }
 
i read in the smarty manual that the correct syntax for increment is as follows

Code:
{assign var="left_line_count" value=[red]`[/red]$left_line_count+1[red]`[/red]}
 
jpadie,

Thanks for your assistance! Here is the code I ended up with
Code:
					{ math equation="x + 1" x=$left_line_count assign="left_line_count" }
					{ if $left_line_count > $max_lines_page }
						<p class="break">&nbsp;</p>
						{assign var="left_line_count" value="18" }
					{ /if }

After further investigation, I found that the template used in this project is "templatelite", a flavor derived from "smarty" ...

Regards,


Jose



--
SouthBeach
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top