Xpages:是否可以在主题中设置内容,以便将资源(如css或SSJS或CSJS)应用于应用程序中的每个Xpage / CC

时间:2016-07-28 18:08:03

标签: themes xpages

我有一个背景渐变,我希望将其应用于从此设计继承的数据库中的所有Xpages中的每个body标记。

我将css资源放在我的模板中,并修改了主题,以便此资源包含在从此模板继承的每个数据库中:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:param name="path-to-lookup" select="'lookup.xml'" />

<xsl:key name="host" match="hostid" use="@name" />

<!-- identity transform -->
<xsl:template match="@*|node()">
    <xsl:copy>
        <xsl:apply-templates select="@*|node()"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="host">
    <xsl:copy>
        <xsl:variable name="host-id" select="." />
        <!-- switch context to lookup document in order to use key -->
        <xsl:for-each select="document($path-to-lookup)">
            <xsl:value-of select="key('host', $host-id)" />
        </xsl:for-each>
    </xsl:copy>
</xsl:template>

</xsl:stylesheet>

是否可以设置某些内容,以便应用程序中的每个Xpage都会自动包含一组资源,除了显而易见的一个只包含这些资源的CC并将其包含在每个X页上?

1 个答案:

答案 0 :(得分:3)

One aspect to bear in mind is that the theme is only applied in the Render Response phase. So if you include an SSJS library, you won't be able to use it in beforePageLoad or afterPageLoad.

A theme is very useful for applying settings default or overridden properties to a specific type of component, e.g. a different open/close image to all sections, a default pageName property on the ViewRoot component (so top-level XPage properties). In terms of adding resources. So the ViewRoot is the control name you need in a theme for the body.

In terms of adding resources etc, unless I'm using "#{javascript:...} to compute settings, I'm not concerned about putting them in a theme rather than a custom control. I usually have a layout custom control. SSJS computed dynamically will only run once per page load / refresh in a theme (just in Render Response), compared to every phase of the lifecycle in a custom control. If it's hard-coded, as in your example, the custom control is as good a place as any.