How do we apply logic in template file of phpBB?
The way they have taught in the tutorial doesnt works for me.
I have used this:
$template->assign_var('POINTER',$pointer);
and in the .tpl file
!-- IF POINTER == 1 -->
do this
!-- ELSE -->
do that
!-- ENDIF -->
But it doesn't work.
1.) Are you using PHPBB3 or 2? Because the IF-Condtion exists only in Version 3.
2.) You know that the "<"-Sign is missing at the begin of your Code?
You have a few errors in your code:
// There wasn't anything wrong with the PHP code
$pointer = 1;
$template->assign_var('POINTER', $pointer);
In the template file:
<!-- IF POINTER == 1 -->
<div>Pointer is 1</div>
<!-- ELSE -->
<div>Pointer is not 1</div>
<!-- ENDIF -->
Errors:
HTML comments (and phpBB instruction blocks) start with <!--
There's only one space after <!-- (you had two for ENDIF)
Related
I was wondering if someone can help me out with this. For my system I made i'm using .tpl files for viewer files. The problem underlays in using if else statements.
Like this would be an example of an tpl file:
<div class="menu">
<li>Home</li>
<!-- Checking if has admin rights -->
[IF='isadmin']
<li>Admin</li>
[ENDIF]
<!-- End of checking -->
</div>
But how can I implent this in PHP?
I already searched in stackoverflow, but only found answers as you just need to use PHP for this. This isn't the right way for me to use PHP. The system is already too complicated to change everything to PHP and using PHP as viewer doesn't pass the requirements.
Thanks in advance!
Your file extension must be not ".html". You need to change it to ".php"
Then you can use PHP in HTML code like :
<div class="menu">
<li>Home</li>
<!-- Checking if has admin rights -->
<?php if ($isAdmin) { ?> // $isAdmin is a boolean
<li>Admin</li>
<?php } ?>
<!-- End of checking -->
</div>
You can affect a boolean into $isAdmin as you want like $isAdmin = true;. If this var is true, <li>Admin</li> will display.
PS : This notation if ($isAdmin) it's the same thing as if ($isAdmin == true).
To try to map up all the pages, I've made a couple of maps called products and similar naming.
However when I go through a link with, for example, product/xxx.php and press the same link within the menu at that page I've entered, I get an adding of products/products/xxx.php, which break the link.
How do you avoid or correct these sort of linkages?
so for example I have my main menu inside a php file called menu.php which I include in the index.php by php include
a snip of the main menu php is
<div class="menuBar">
<ul id="menu">
<li>xxx
<div class="dropdown_unit">
<!-- Header -->
<div class="unitSizer">
<h4>xxx</h4>
</div> <!-- END Header -->
and it is placed within a div at the index.php
like this:
<div class="menuBar">
<?php include 'menu.php'; ?>
</div> <!-- END menuBarDental -->
this is just 1 part of the menu but it looks the same overall inside the menu.php
the problem here is that it seems by include this php file into the index.php and generating
the links inside the menu it keeps adding instances of the links.
I am reading a TYPO3 extension.
This is the template file:
<!-- ###LIST_LATEST### begin -->
<div class="latest-wrapper">
<ul class="listing latest">
<li><h1>###LIST_HEADER###</h1></li>
<!-- ###LOOP### --><!-- ###ITEM### --><li>
<span class="category">###CATEGORY###</span><span class="company">###COMPANY_NAME###</span><span class="location">###LOCATION###, ###STATE### ###ZIP###</span>
</li><!-- ###ITEM### --><!-- ###LOOP### -->
<li class="more">###MORE###</li>
</ul>
</div>
<!-- ###LIST_LATEST### end -->
In class.tx_jcjob_pi1.php, when put the contents into the template file, seems there are two ways:
a. for ###MORE###, use this method:
$markerArray['###MORE###'] = $this->cObj->getTypoLink($this->pi_getLL('text_link_more'), $this->conf['searchID'], array('tx_ajaxsearch_pi1[keyword]' => ''));
$content = $this->cObj->substituteMarkerArray($template, $markerArray);
b. for <!-- ###LOOP### -->, use this method:
$template = $this->cObj->substituteSubpart($template, '###LOOP###', $loopContent); var_dump($template);
So my question is:
What is the difference between ###MORE### and <!-- ###LOOP### -->?
What is the difference between substituteMarkerArray and substituteSubpart?
You are asking for the difference between two basic templating tools in TYPO3:
Markers (###MORE###) and
Subparts (<!-- ###LOOP### -->)
Both are placeholders to be replaced with dynamic content.
A marker represents a singular occurance. The string ###MORE### will be replaced by the function substituteMarker() or substituteMarkerArray() with whatever value you define in your php code.
A subpart always occurs in pairs; it has a beginning and an end marker. They enclose a range of code within which more values can be replaced. In your case, everything between the two <!-- ###LOOP### --> strings you find in your template can be processed by the function substituteSubpart(). Usually, this is used for list views when you loop over multiple results from your query. Within each subpart element you can replace markers or subparts recursively in your php code.
This blog post might give you some more insight into the principles.
I'm trying to handle a control case where a variable is not defined.
This is what seems to work, but is also ugly. Any ways to make this work better?
<!-- IF UNASSIGNED_VARIABLE -->
<!-- ELSE -->
<insert code here>
<!-- END -->
I tried a few different negation structures, but they only worked when the template variable was defined.
Common operators are described on the wiki
<!-- IF not UNASSIGNED_VARIABLE -->
<insert code here>
<!-- END -->
For most of my projects I make an administration interface, which has the same design for every project. The design of the header, the footer, the topbar, the leftmenu, the css, etc. are always the same. It is a pity to create the views every time; so I was thinking: maybe there would be a nice way to put the admin interface in my MVC library, as it is reused by every project?
But for the moment, in every single view I got code like the following:
<?php $this->_include('/includes/doctype.php'); ?>
<head>
<?php $this->_include('/includes/head.php'); ?>
<title>Some title</title>
</head>
<body>
<?php $this->_include('/includes/topbar.php'); ?>
<div id="page">
<?php $this->_include('/includes/header.php'); ?>
<?php $this->_include('/includes/leftmenu.php'); ?>
<div id="content" role="main">
<h1>Some title</h1>
<p>Blah blah blah.</p>
</div><!-- /#content -->
<?php $this->_include('/includes/footer.php'); ?>
</div><!-- /#page -->
</body>
</html>
Would it be a good idea to extract the custom content from the structure of the interface, and put that structure in my library somehow to make it reusable?
After that how will it be possible to customize the title and the actual menus?
I do this all the time. I have a custom header and footer file that are called at the start and end of every page.
<?PHP
Require("includes/header.php");
...
Require("includes/footer.php");
?>
The header provides a database handle, a datetime string and handles logon, priveleges, logging of pageviews etc.
The footer provides a standard HTML page but includes some systematised variables. It also generates the menu dynamically from the driving database then closes the database connection.
This way when I write code, I don't get mixed up in the HTML and any bugs are easy to find.
I like variables akin to:
$display_scripts - adds extra data in the head section.
$display_onload_scripts - adds onload scripts to body section.
$display_style_sheets - option to include link to additional stylesheets
$display_above_menu - will appear above the menubar. NOT recommended.
$display_below_menu - will appear immediately below the menubar.
$display_one_column - page contents when only one column is to be used
$display_left_column - page contents when two columns used. Left pane.
$display_right_column - page contents when two columns used. Right pane.
$display_footer - appears in footer division.
My main code then just has to generate the appropriate variable. Fundamentally, what you need to do is examine the source of a good age you have produced then replace the stuff you want to change with variables.
Here is a schematised version of the file I use (pseudocode) to give you an idea of how I do it.
// Code here generates the menu from database
// Code here genereates popup alert messages from other users
//permanent links to external style sheets go here.
//You can also select skins here.
<?PHP
echo $display_style_sheets;
echo "<title>".$display_page_title."</title>";
?>
<script type="text/javascript" src="JAVASCRIPT GOES HERE.js"></script>
</head>
<body <?PHP echo $display_onload_scripts;?> >
<div id="page_area" >
<div id="banner">
</div>
<?php
echo $display_above_menu;
if(!$hide_menu){echo $display_menu;} //Insert the menu variable here.
echo $display_below_menu;
?>
<div id="content_area">
<div id="inner_content">
<?PHP
if($display_number_of_columns==1)
{
echo "<div id='onecolumn'>".$display_one_column."</div>"; //I only use this one
}
if($display_number_of_columns==2)
{
echo "<div id='leftcolumn'>".$display_left_column."</div>"; //these are left for legacy support from before I got better at CSS.
echo "<div id='rightcolumn'>".$display_right_column."</div>";
}
echo "<div id='footer'>".$display_footer."</div>"; //just in case - I hardly use it.
echo $display_pop_box; //for user alert messages to other users
?>
</div>
</div>
</div>
<div id="logbox"> Automatic Logout statement</div> //this is called by JS to activate timeouts.
</body>
</html>
<?PHP
$mysqlidb->close();
?>
Sorry it's such a lot of code. The layout allows easy adaptation and makes it simple to find the offending variable if things are not going as expected. There are more elegant solutions but this works well for me and is very fast.