[英]How to add PHP or Javascript code to a custom content type
I am working with Drupal 7.17. 我正在使用Drupal 7.17。
I have a custom content type I created called Sidebar Ad (machine name sidebar_ad) that I want to add Javascript and PHP to. 我创建了一个自定义内容类型,称为Sidebar Ad(机器名称sidebar_ad),我想向其中添加Javascript和PHP。 From what I understand, in the templates directory of the theme I am working with, I need to create a file called 'page--sidebar_ad.tpl.php' and I can put PHP and Javascript code in there, and it will only run in blocks and pages that contain the custom content type Sidebar Ad.
据我了解,在我正在使用的主题的模板目录中,我需要创建一个名为“ page--sidebar_ad.tpl.php”的文件,然后将PHP和Javascript代码放入其中,并且该文件只能运行在包含自定义内容类型“边栏广告”的块和页面中。
I am trying this out with one of the stock themes, Bartik, and it is not working for me. 我正在使用股票主题之一Bartik进行尝试,但它对我没有用。 I tried it by copying the page.tpl.php file, renaming it page--sidebar_ad.tpl.php, and adding a bit of text in a few places - at the top of the php file, and in the content div.
我通过复制page.tpl.php文件,将其重命名为page-sidebar_ad.tpl.php并在php文件顶部和内容div中的几个位置添加了一些文本来进行尝试。 But I don't see anything change on the pages on my site that contain that custom content type.
但是,我看不到网站上包含该自定义内容类型的页面上的任何更改。
Is there something I am missing? 我有什么想念的吗?
Most likely the thing you're missing is flushing Drupal's cache...any time you add a hook or template file, you need to flush the cache so the various registries can pick it up. 您丢失的东西很可能是刷新Drupal的缓存...每次添加钩子或模板文件时,都需要刷新缓存,以便各个注册表都可以提取它。
In the case of an overridden page template file you also need a copy of the standard page.tpl.php file in your theme. 对于覆盖的页面模板文件,您还需要主题中标准page.tpl.php文件的副本。 Same goes for the node template and most likely others, you need the original in there for the overrides to work.
节点模板和其他模板也一样,您需要原始模板才能使覆盖生效。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.