【问题标题】:want to call one phtml file in another phtml file using anchor tag想使用锚标记在另一个 phtml 文件中调用一个 phtml 文件
【发布时间】:2016-09-08 15:28:00
【问题描述】:

我正在使用 Magento。

我想显示并调用一个phtml 文件作为另一个phtml 文件中的链接...

我在主页上有new.phtml 文件。在那我放了一个链接检查所有显示所有新产品作为类别页面。它看起来像类别页面。为此,我创建了另一个名为newproductpage.phtmlphtml 文件,其代码与new.phtml 相同。现在我尝试将此newproductpage.phtml 文件@homepage 称为我编写此代码的CHECK ALL 链接....

<a href="<?php echo $this->getUr('newproductpage.phtml')?>">CHECK ALL</a>

但它不起作用....

thnx..

【问题讨论】:

标签: php magento hyperlink


【解决方案1】:

您可以使用以下代码在任何 phtml 文件中调用 newproductpage.phtml

<?php echo $this->getLayout()->createBlock('core/template')->setTemplate('custom/newproductpage.phtml')->toHtml(); ?>

【讨论】:

    【解决方案2】:

    使用以下代码在另一个 phtml 文件中呈现您的 phtml 文件。

    <?php echo $this->getLayout()->createBlock('core/template')->setTemplate('templatefolderpath/filename.phtml')->toHtml(); ?>
    

    为了更细化您的代码,您可以使用块名称和块文件名代替 core/template,因为 core/template 使用核心资源。

    【讨论】:

      【解决方案3】:

      您不能直接将一个 phtml 文件调用到另一个 phtml 文件。

      但是有两种方法可以调用您的 phtml 文件,或者创建一个控制器并创建一个操作并从您的锚标记调用操作,或者创建一个调用您的 phtml 文件的 cms 页面。

      如果你创建一个模块,那么在你的布局文件中你可以写一些东西

      <modulename_controllername_controlleraction>
          <reference name="content">
              <block type="catalog/product_new" template="custom/newproductpage.phtml" />
          </reference>
      </module_controllername_controlleraction>
      

      或者你可以直接把这段代码放在你的cms页面内容区

      {{block type="catalog/product_new" template="custom/newproductpage.phtml"}}
      

      并在锚标签中给出cms页面链接。

      【讨论】:

      • 如果我想在 new.phtml 中显示 addnewproduct.phtml 作为链接...怎么办?
      • 我想说的是,在 new.phtml 文件中,我给出了名为 CHECK ALL 的锚标记,然后单击该 newproductpage.phtml 文件将打开..我对此感到困惑。而且你.. new.phtml 没有 XMl 文件。 new.phtml 文件在主页中作为块调用。
      • 只需将您的 cms 页面链接添加到您的锚类别链接中,然后在 cms 页面中输入此代码{{block type="catalog/product_new" template="custom/newproductpage.phtml"}}
      • 兄弟,我不想在主页上调用这个块...我已经把New.phtml和new.phtml = newproductpage.phtml的块,两者都有相同的功能来查看新产品。不同之处在于 new.phtml 用作主页上的一个块,其他块带有滑块。而 newproductpage.phtml 是一个完整的页面,看起来像一个带有左侧边栏的类别页面,其中显示购物、比较产品、社区民意调查、流行标签等,并且主要有所有新产品......所以你能给我任何建议吗...... !
      【解决方案4】:
      <?php echo $this->getLayout()->createBlock('core/template')->setTemplate('catalog/product/new.phtml')->toHtml(); ?>
      

      您也可以查看链接。

      Display .phtml page in another .phtml page

      【讨论】:

        【解决方案5】:

        我相信你和我都想做同样的事情。我正在从引导程序创建一个模式,我需要使用 href attr 调用部分。

        到目前为止,我认为这可以通过在 CMS 中创建一个页面然后使用类似的东西来实现:

        <li><a href="<?php echo $this->getUrl("page-name-in-CMS") ?>">Home</a></li>
        

        但老实说,我才刚开始使用 Magento,而且了解的很少。

        【讨论】:

        • thnx 兄弟..我们可以创建相同的代码 cms 页面并使用锚点调用它...!!
        • 这是否意味着我的回答帮助您解决了问题?如果是这样,请投票给我的答案并选择它! :)
        【解决方案6】:

        您可以使用 iframe 并使用 AJAX 调用加载另一个页面内容

        【讨论】:

        • iframe 和 ajax 会让事情变得更复杂,而是直接使用这段代码定义块和模板文件。 getLayout()->createBlock('core/template')->setTemplate('custom/newproductpage.phtml')->toHtml(); ?>
        猜你喜欢
        • 1970-01-01
        • 2014-04-28
        • 2016-03-21
        • 2016-09-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多