开发者

How to add <span> tags inside Plone <h1> element

I want to change the standard top of page element so that I can style it.

<h1 class="documentFirstHeading">My Heading</h1>

is the开发者_如何学Python way Plone places this element on each page. I want to add a so that the line reads:

<h1 class="documentFirstHeading"><span>My Heading</span></h1>

It's obvious that this code is generated by a macro - but I have no idea how to modify the macro to add my span tags. Can someone point me to the appropriate Plone file to modify? This sets up a common CSS image replacement technique, and other Plone sites frequently use it, as I see the span tags exactly where I need them to be, on other Plone sites.

TIA for your expertise!


it doesn't really matter (the actions are pretty much the same), but I assume you are creating the theme package. I also assume you're on Plone 4.0 or newer. The actions are:

  • Copy over *kss_generic_macro.pt* file, located in *Products.CMFPlone/Products/CMFPlone/skins/plone_kss* to your theme's *skins/your_templates_folder*. In generic terms this is called "customize the template to your theme".
  • On line 20 (line number might differ in different Plone versions), you will find the block you need:

    title

To get the span within your h1, replace tal:replace in the snippet above to tal:content.

You might need to restart your Plone site in order to see your change in action. Check your h1 — it should contain the span you need.

Important note! Actions above will give you within for every generic view that doesn't have specific template, overriding . For those cases you will need to customize those particular templates.


I am not 100% sure (edits welcome :-D), and I am not sure about what you want with that either, but I think you will need to customize the Page view template.

In Plone 3.x, the template is the /portal_skins/plone_content/document_view template, and you probably will want to change

    <h1 class="documentFirstHeading"> 
        <metal:field use-macro="python:here.widget('title', mode='view')">
        Title
        </metal:field>
    </h1>

to

    <h1 class="documentFirstHeading"> 
        <span>
        <metal:field use-macro="python:here.widget('title', mode='view')">
        Title
        </metal:field>
        </span>
    </h1>

In Plone 4 and 4.1, the key template is portal_skins/plone_kss/kss_generic_macros. Look for:

      <span metal:define-slot="inside" 
            tal:replace="context/Title">title</span>

and change the "replace" to "content".


Thanks to spliter, I now have the styling for the Section pages done. As he mentioned, the changes also affected all generic views that don't have specific template overrides. I am guessing that these are things like the Detail view, which is what comes up when one clicks on alink to a particular article under a given Section.

So, although my Section pages display as intended, when I click on an article, this is what happens:

If I set the text between span tags to display:none, that behavior is NOT reflected in the detail pages at all, as the span is not applied inside the h1 tags on detail pages.

BUT, since I am setting particular background images for the h1 elements on the Section page, that background image DOES appear on the detail page h1's.

How do I override that behavior for my detail pages? - that is, I DON'T want background images on detail page h1 elements. I need to be able to address h1 elements on Section and Detail pages separately.

Sorry for my lack of experience here, but getting used to the way Plone works seems to be time-cosuming, at least for me.


after doing some poking around for you I was able to figure out that the macro you're looking for is located at '/portal_skins/plone_kss/kss_generic_macros/' specifically you're looking for the 'generic_title_view macro'.

If you're wondering how I got this, I looked first at the main_template.pt file and saw:

<metal:title define-slot="content-title">                              
    <metal:comment tal:content="nothing">
        If you write a custom title always use 
        <h1 class="documentFirstHeading"></h1> for it
    </metal:comment>
    <h1 metal:use-macro="context/kss_generic_macros/macros/generic_title_view">              
       Generic KSS Title. Is rendered with class="documentFirstHeading".                    
    </h1>                                                                                    
</metal:title>

and from there I just poked around in the skins looking for kss, Hopefully this was what you were looking for.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜