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 -->
Related
When I add block Social links in the template part and after that choose this template part with block Template part - nothing is rendering. Why it's happening? Maybe attributes don't pass trough blocks in this case? but it looks like a bug in the core.
<!-- wp:social-links -->
<ul class="wp-block-social-links">
<!-- wp:social-link /-->
</ul>
<!-- /wp:social-links -->
Or when I create a template part like this - is any possible way to pass dynamically attributes from the editor to template part instead hardcoded url?
<!-- wp:social-links -->
<ul class="wp-block-social-links">
<!-- wp:social-link {"url":"https://wordpress.org/patterns/","service":"instagram"} /-->
<!-- wp:social-link {"url":"https://wordpress.org/patterns/","service":"bandcamp"} /-->
<!-- wp:social-link {"url":"https://wordpress.org/patterns/","service":"twitter"} /-->
<!-- wp:social-link {"url":"https://wordpress.org/patterns/","service":"twitch"} /-->
I try to add block Social Links in the template part and need to have the opportunity to choose template part with social links with block Template Part. And seeing results on the frontend.
When the Social Links block is inserted into the template part, a valid link for each social you add, eg "Instagram", "Bandcamp", etc... is required otherwise it will not render a link on the frontend - producing the markup posted in your question.
To insert the Social Links block into multiple template parts without having to set the URLs each time, convert your configured Social Links block to a Reusable Block. By using a Reusable Block in your templates, you will also be able to easily update/add/remove your social links site-wide in the future if needed.
I was wondering if there is a way to enable PhpStorm (or any other JetBrains tool that deals with .phtml files) to recognize conditional blocks when collapsing units of code.
I have this example:
<div class="parent">
<?php if (condition) : ?>
<div class="div1">
<?php elseif (conditionTwo) : ?>
<div class="div2">
<?php endif; ?>
<!-- Conditional block ends here -->
</div>
<!-- Parent container ends here -->
</div>
PhpStorm (by default) allows me to collapse div2 (with the first </div>), therefore div1 will need to collapse with the last </div>, which is meant to be collapse with parent.
I have attempted to adjust settings, but with no success.
Microsoft's Visual Studio Code has the correct behavior:
As you can see, in VSCode you are not allowed to collapse on <div>'s that are inside the php if block.
Thanks for your time.
This can't be configured with given code sample. You can submit this to JetBrains tracker at https://youtrack.jetbrains.com/newIssue for developers to look into it & address in next IDE versions.
Really, the issue here is how you're writing the code. It would be cleaner (and remove the edge case of not having a final else if you did something like
<div class="<?= condition ? 'div1' : 'div2'; ?>">
I'm implementing a custom php script within the viewforum loop to add voting. I need to pass {topicrow.TOPIC_ID} to the voteHTML(), where $itembid currently is. It renders the data-did perfectly through the loop. How do I get the variable value through to the php block?
<span class="topid" data-did="{topicrow.TOPIC_ID}" ></span>
<!-- PHP -->
echo $pulse->voteHTML($itembid);
<!-- ENDPHP -->
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.
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)