Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
224 views
in Technique[技术] by (71.8m points)

mura - ColdFusion: Passing a variable from an include back up to the parent page

I'm using Mura CMS 7.1, which uses ColdFusion. On a page template I have some markup and am including a template file that has code for displaying calendar events from an outside source. When there are no events, I'm currently displaying a message as such. Instead however, I'd like to hide this entire section on the page template itself. Problem is I need to pass some sort of value from the include file back to the page template so I can set inline CSS to either display block/none for this section, and I'm not sure how to do this. My page template code is:

        <section class="collegeEvents" style="display:">
            <div class="collegeEvents__container wrapper-1170MaxWidth">
                <h2 class="collegeEvents__heading">What's coming up?</h2>
                <cfinclude template="inc/homeEvents.cfm" />
            </div>
        </section>

And the calendar code is all inside of the 'homeEvents.cfm' file. I need to be able to alter that inline css 'display' property with a value that I set in 'homeEvents.cfm'. How would I go about doing this so that the value is accessible from the page template?

question from:https://stackoverflow.com/questions/65905003/coldfusion-passing-a-variable-from-an-include-back-up-to-the-parent-page

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I'm not suggesting this is good practice, but you could use a style block from code inside your included cfm. eg:

<cfsavecontent variable="variables.styleBlock">
    <style>
    <cfif myLogicHere>
        .collegeEvents {display:none;}
    <cfelse>
        .collegeEvents {display:block;}
    </cfif>
    </style>
</cfsavecontent>
<cfhtmlhead text="#variables.styleBlock#" />

You could also use javascript to change the style afterwards, but with that there's more chance of a delay where the user sees the 'wrong' layout before the style is eventually applied.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...