[英]PHP If state - Render HTML only if there is text output from Joomla module text field int the backend
我尝试在Joomla 3中构建一个简单的FAQ模块。
我在模块后端有4个字段。 “问题1和答案1”“问题2和答案2”。
我的php和HTML的构建方式如下:
<div id="accordion">
<h3 class="question"> <?php echo $params->get('question1'); ?></h3>
<div class="question">
<?php echo $params->get('answer1'); ?>
</div>
<h3 class="question"> <?php echo $params->get('question2'); ?></h3>
<div class="question">
<?php echo $params->get('answer2'); ?>
</div>
</div>
我喜欢用if语句添加一些php,这样,如果用户填写了文本字段,则代码块仅在后端的文本字段出现时才呈现:
(如果“ question3”字段中有任何文本,请显示此代码)
<?php if ($this->params->get('question3')) : ?> //This is the line of code i do not know how to do.
<h3 class="question"> <?php echo $params->get('question2'); ?></h3>
<div class="question">
<?php echo $params->get('answer2'); ?>
</div>
</div>
<?php endif; ?>
XML如下所示:
<!-- Question 1 -->
<field
label="Question 1"
default=""
name="question1"
description="Fill in the question"
type="text"
size="60"
/>
<!-- End of Question 1 -->
<!-- Answer 1 -->
<field
label="Answer1"
default="Fill in the answer"
name="answer1"
description="Fill in the answer"
type="editor"
width="200"
height="100"
hide="readmore,pagebreak"
filter="safehtml"
size="260"
/>
<!-- End of Answer 1 -->
<field type="spacer" name="questionspacer2" label="<b>Question and Answer 2 1</b>" />
<!-- Question 2 -->
<field
label="Question 2"
default=""
name="question2"
description="Fill in the question"
type="text"
size="60"
/>
<!-- End of Question 2 -->
<!-- Answer 2 -->
<field
label="Answer2"
default=""
name="answer2"
description="Fill in the answer"
type="editor"
width="200"
height="100"
hide="readmore,pagebreak"
filter="safehtml"
size="260"
/>
<!-- End of Answer 2 -->
任何提示都会很棒! 我已经整夜都在寻找解决方案。
根据未设置参数时如何设置参数,您需要检查输出,如下所示:
$answer2 = $params->get('answer2'));
// (Applies if the not filled data returns NULL etc.)
if ( isset($answer2) ) { YOUR CODE }
// (Applies if the not filled data returns an empty string)
if ( !empty($answer2) ) { YOUR CODE }
未经测试,但它应该可以工作;)
编辑:只是使它看起来应该像下面的评论中讨论的那样:)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.