English 中文(简体)
Snippet使用页数(ModX, 1.0.5)
原标题:Use page variables in Snippet (ModX, 1.0.5)
  • 时间:2012-05-06 21:08:53
  •  标签:
  • modx

(Using ModX 1.0.5)

When I execute my current snippet (see snippet below), it seems to completely ignore the if(empty()) checks. I have also tried with if($promoX == ), also no luck.

<?php
    $promo1 =  [*sidepromotop*] ; // assets/images/promo1.jpg
    $promo2 =  [*sidepromobot*] ; // this variable is empty.

    if(empty($promo1) && empty($promo2)){
       echo  [!Ditto? &startID=`92` &depth=`1` &display=`2` &randomize=`1` &tpl=`Promo-Block-Styles`!] ;
    }else{
       if(empty($promo1)){
          echo  [!Ditto? &startID=`92` &depth=`1` &display=`1` &randomize=`1` &tpl=`Promo-Block-Styles`!] ;
       }else{
          echo  <div class="promo"><img src=" .$promo1. " alt="" /></div> ;
       }
       if(empty($promo2)){
          echo  [!Ditto? &startID=`92` &depth=`1` &display=`1` &randomize=`1` &tpl=`Promo-Block-Styles`!] ;
       }else{
          echo  <div class="promo"><img src=" .$promo2. " alt="" /></div> ;
       }
    }
?>

以上准则出于某种原因将显示如下:

<div class="promo">
    <img src="assets/images/promo1.jpg" alt="">
</div>
<div class="promo">
    <img src="" alt="">
</div>

你可以看到,即使变量是空的,在我通过我的法典管理这一变量时,它显然仍然认为它不是空洞的。

我真的希望能看到这方面的一些见解,因为我是新鲜的,我是这样一位头脑!

感谢!

最佳回答

MODX 标签,如[* E/CN.6/2009/1。sidepromotop* E/CN.6/2009/1。],不在单薄板(原为php)之内,因此实际上,空洞()检查工作正在完美地进行,因为你正在把未铺设的标签作为扼杀。

你们需要做的是利用) 检索现有文件模板:

$promo1 = $modx->getTemplateVar( sidepromotop );

或者,你可以把这些要素作为参数纳入你的幻灯塔。

[!mySnippet? &promo1=`[* E/CN.6/2009/1。sidepromotop* E/CN.6/2009/1。]` &promo2=`[* E/CN.6/2009/1。sidepromobot* E/CN.6/2009/1。]`!]

......这些变量将作为<代码>$promo1和_$promo2在您的snippet代码中提供。

* E/CN.6/2009/1。

您还应使用$modx->runSnippet()执行Ditto在氮内,其效率将大大提高。

$output = $modx->runSnippet( Ditto , array(
     startID    => 92,
     depth      => 1,
     display    => 1, 
     randomize  => 1,
     tpl        =>  Promo-Block-Styles ,
));
return $output;

Check out this wiki article for some great tips for creating snippets for MODX: http://wiki.modxcms.com/index.php/Creating_Snippets

问题回答

暂无回答




相关问题
predefine template for new resource/document

I would like to set the new child documents to default to a set template that is different from the parent. I ve looked through managermanager, but looks like it is unable to do this. mm_inherit can ...

Modx css issue not pulling in styles on the form

I m editing a site using Modx cms. I m trying to add a contact form to the contact page. I already have one in the sidebar specified in a template. The code on the contact page form points to the same ...

PHP MODx mysql Parse error? Where do I change the settings?

Hi I m using MODx on a site, but something has gone wrong with the database. Any idea how I can change the PHP to point to my database? « MODx Parse Error » MODx encountered the following error while ...

Print a table in modx to send info for mail by eForm

My question is, how can I create a table with dynamic fields (I will explain this later), and send them values by mail with eform? In the table, on the left, I want to print all the document children ...

Simple PHP CMS as an alternative to hacking Wordpress

For creating common user modifiable site I ve been forcing Wordpress to do the work of a CMS. It s worked and the back-end is purdy but it s just too hacky for my tastes. So I d like a simple CMS that ...

Modx assign default date to template variable

I have a template variable of input type date but I d like to have a default value of the current date at the time the document was first saved. I ve noticed that using the date formatter widget ...

热门标签