Does anyone know how to manage libraries in Dreamweaver for CommonSpot? (I'm very new to CommonSpot).
CommonSpot is returning an error wherever I use # symbol. Somehow I managed to remove all of the # symbols from the libraries. But I want to create libraries in Dreamweaver which defines a library as starting with:
<!-- #BeginLibraryItem ...
This causes a problem because of the # symbol.
Does CommonSpot have anything like library? Or are there any escape characters I can use to achieve this?
CF must be evaluating the comment. Here are a couple ideas.
Check if there is a cfoutput tag around the entire file. If so, adjust them to not be around the comment
If currently this
<cfoutput>
...
<!-- #BeginLibraryItem ... -->
...
</cfoutput>
try this
<cfoutput>
...
</cfoutput>
<!-- #BeginLibraryItem... -->
<cfoutput>
...
</cfoutput>
Another option that might work depending on exactly how the library comments are evaluated is to make them CFML comments with 3 dashes instead of 2 to have the # ignored
like so...
<!--- #BeginLibraryItem ... --->
Related
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?
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.
This is a formatted comment.
I know that variables in the calling page are available in the included page. This leads me to believe that variables in the included page are available to the calling page. Here is a simple test of that theory.
CallingPage.cfm
<cfinclude IncludedPage.cfm>
<cfdump var = "#x#">
IncludedPage.cfm
<cfset x = 1>
Browse CallingPage.cfm and see what happens. If you get an error for an undefined variable, there is always to good old session scope.
Please see the comment from #haxtbh. I was able to accomplish the desired task using JS directly within the include.
I'm trying to read some values from the XML file which I created, but it gives me the following error:
coldfusion.runtime.UndefinedElementException: Element MYXML.UPLOAD is undefined in XMLDOC.
Here is my code
<cffile action="read" file="#expandPath("./config.xml")#" variable="configuration" />
<cfset xmldoc = XmlParse(configuration) />
<div class="row"><cfoutput>#xmldoc.myxml.upload-file.size#</cfoutput></div>
Here is my config.xml
<myxml>
<upload-file>
<size>15</size>
<accepted-format>pdf</accepted-format>
</upload-file>
</myxml>
Can someone help me to figure out what is the error?
When I am printing the entire variable as <div class="row"><cfoutput>#xmldoc#</cfoutput></div> it is showing the values as
15 pdf
The problem is the hyphen - contained in the <upload-file> name within your XML. If you are in control of the XML contents the easiest fix will be to not use hyphens in your field names. If you cannot control the XML contents then you will need to do more to get around this issue.
Ben Nadel has a pretty good blog article in the topic - Accessing XML Nodes Having Names That Contain Dashes In ColdFusion
From that article:
To get ColdFusion to see the dash as part of the node name, we have to "escape" it, for lack of a better term. To do so, we either have to use array notation and define the node name as a quoted string; or, we have to use xmlSearch() where we can deal directly with the underlying document object model.
He goes on to give examples. As he states in that article, you can either quote the node name to access the data. Like...
<div class="row">
<cfoutput>#xmldoc.myxml["upload-file"].size#</cfoutput>
</div>
Or you can use the xmlSearch() function to parse the data for you. Note that this will return an array of the data. Like...
<cfset xmlarray = xmlSearch(xmldoc,"/myxml/upload-file/")>
<div class="row">
<cfoutput>#xmlarray[1].size#</cfoutput>
</div>
Both of these examples will output 15.
I created a gist for you to see these examples as well.
Consider test.cfm file with the following content:
<html>
<body>
<cfif foo EQ bar>
<cfset test = "something" />
</cfif>
<p>Hello!</p>
</body>
</html>
When run in the browser, the source code of the output of this file will look like this:
<html>
<body>
<p>Hello!</p>
</body>
</html>
Is there any way to fix this?
Is there any way to fix this?
There's nothing to fix - the HTML is perfectly valid and functional.
If your issue is the size of request, use gzip encoding.
If your issue is reading the source for debugging/etc, use developer tools such as Firebug/etc.
However, general things you should be doing to improve maintainability (which at the same time also reduces whitespace output) are:
1) Move anything that isn't display logic out of your views.
2) Convert display logic to functions and custom tags as appropriate, which both make it easier to prevent/control output.
To prevent unwanted content being output, you can:
Wrap the entire section in cfsilent, to ensure nothing gets output.
Enable enablecfoutputonly attribute of cfsetting then only use cfoutput around things you want to be output.
Always set output=false on component and function tags.
When you want to selectively output some text, wrap non-tag non-output segments in CFML comments <!---...---> (e.g. useful for preventing newline output in custom tags)
(I never bother with cfprocessingdirective, everything mentioned above solves the issues better.)
If you have access to the CF Administrator, there is an option to suppress white space.
It is under 'Server Settings' --> 'Settings' its called 'Enable Whitespace Management'.
Try <cfprocessingdirective suppressWhiteSpace="true">
Reference: http://help.adobe.com/en_US/ColdFusion/9.0/CFMLRef/WSc3ff6d0ea77859461172e0811cbec22c24-76de.html
I’ve created a file index of all of my ColdFusion files so I can quickly search the files and find what I’m looking for. So far, it’s working great except it doesn’t seem to be searching inside any ColdFusion tags.
For example…
<p>If I searched for this text, It would return a result</p>
<cfset variables.foo = "however, If I search for this text it wouldn’t return any results." />
Does anyone know if there’s a way to search inside of a ColdFusion tag like that?
This is my index..
<cfindex
collection = "fileIndex"
action="refresh"
type="path"
key="d:\my-websites-location\"
urlpath="http://mywebsite/"
extensions=".cfm, .cfml, .cfc"
recurse="Yes">
This is my search…
<cfsearch
name = "testSearch"
collection = "fileIndex"
type="internet"
criteria = "variables.foo"
/>
Any ideas?
Thanks,
Paul : )
It looks like the type="internet" may be your issue. Try removing the "type" attribute and see what you get.
Use a query that does get the record and look at the "summary" field of your result. I suspect the markup is being stripped.
On ColdFusion 9, with solr it doesn't index the markup, however Verity does. A workaround you could use a combination of cffile/cfdirectory to read each file one by one and feed it into the collection. This will preserve the markup and make it searchable.
Or you can enclose your criteria variable with ##.
<cfsearch
name = "testSearch"
collection = "fileIndex"
type="internet"
criteria = "#variables.foo#"
/>
I'm creating a set of ColdFusion custom tags designed to make reusing certain layout elements easy. I'll be using them in a manner similar to the following:
<cfimport prefix="layout" taglib="commonfunctions/layouttags">
<layout:fadingbox>
This text will fade in and out
</layout:fadingbox>
<layout:stockticker>
This text will scroll across the screen
</layout>
In order for the code these custom tags generates to work, a JavaScript file needs to be linked into the page like so:
<script src="commonfunctions/layouttags/enablingscript.js" type="text/javascript"></script>
I'd prefer to include the script from inside the custom tags, instead of making the user include it himself. The issue is that the JavaScript file should only be included once per page. After the first time one of these custom tags is used, I'd like subsequent calls to the same tag on the same page to avoid repeating the <script> tag. It's occurred to me that I could do something like this:
<cfif NOT isDefined("Caller.LayoutTagInitialized")>
<script src="commonfunctions/layouttags/enablingscript.js" type="text/javascript"></script>
</cfif>
<cfset Caller.LayoutTagInitialized = 1>
...but it seems inelegant.
I wonder, is there a better way?
How would you implement this?
Edit - Clarification:
In case what I wrote above didn't make sense, here's a more detailed example:
If I have a custom tag like this:
<cfif ThisTag.ExecutionMode EQ "start">
<script src="commonfunctions/layouttags/enablingscript.js" type="text/javascript"></script>
<div class="mytag">
<cfelse>
</div>
</cfif>
...and I have CFML markup calling the tag like like this:
<layout:mytag>
One
</layout:mytag>
<layout:mytag>
Two
</layout:mytag>
<layout:mytag>
Three
</layout:mytag>
...I want HTML like the following to be generated:
<!-- Script included only the first time the tag is called -->
<script src="commonfunctions/layouttags/enablingscript.js" type="text/javascript"></script>
<div class="mytag">
One
</div>
<!-- No <script> tag on the second call -->
<div class="mytag">
Two
</div>
<!-- No <script> tag on the third call -->
<div class="mytag">
Three
</div>
Use the Request scope.
Your solution isn't far off.
Sam's right that the executionmode is what you want to use when you're wanting something to come out in the start or end mode of the tag, which is part of what you want.
But then you say you want that script tag put out in the start mode of only the first tag used on the page.
That's where you would use Peter's suggestion of the request scope. Unlike the default (or "variables") scope, the request scope is shared among all custom tags on a given request. You proposed using the caller scope, and that could work, too, unless the caller was another custom tag, in which case the caller scope would only be the local scope in the custom tag. The request scope (which has been around since about CF 4.01) is your best choice.
In that case, your proposed solution was close: in the custom tag, in the start mode, programatically check if you have already created a tracking variable in the request scope when you put the script tag out the first time. If not, put out the script tag and create the tracking variable.
Other than changing your code from using caller to request, I'd also suggest you'd want to put the CFSET inside the IF. No need to execute it again for when the IF test fails.
Custom tags have a built in scope called thistag.
This code will work:
<cfif thisTag.ExecutionMode eq "start">