This is an update to a post I wrote a couple months ago regarding link insertion into the body of content objects: http://jake.cfwebtools.com/2008/02/29/farcry-insert-link-to-other-dmhtml-objects/. I’d like to formally apologize for my ignorance when writing that post. Please ignore it :).
The problem was that the site tree and the body editor are in two different iFrames causing focus to be lost when clicking on the site tree to try to insert a link. I had a brilliant idea (so I thought) to edit the core files of farcry to fix this. It worked fine, but hey, you had to edit the core files of Farcry. THIS IS NOT A GOOD IDEA! Here’s a better idea…
Why not create your own widget and extend whatever content type you want to use it in? Most likely you want to use it in dmHTML so copy the dmHTML.cfc and _dmhtml folder from /farcry/farcry_core/packages/types to your project folder/packages/types. You can move _dmHTML to your project/system folder if you want. Daemon recommends this as do most of the developers out there. Personally, I don’t see a difference one way or another.
Add a folder called tags inside your project folder and a widgets folder inside that. You can put these anywhere because you’re just going to import a taglib. I think this is the best way to organize it to follow the method that’s already implace in the core files. So, add a .cfm file inside your new widgets folder called whatever you want (I called mine bodyInsertLink.cfm). Here’s the code in my file:
<cfoutput>
<cfquery name="getHTMLPages" datasource="#application.dsn#">
SELECT label,objectid
FROM dmHTML
WHERE status = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="approved">
UNION
SELECT label,objectid
FROM dmInclude
WHERE status = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="approved">
ORDER BY label ASC
</cfquery>
<script type="text/javascript" language="JavaScript">
function getLinkValueInsert()
{
objSelect = document.getElementById("links");
tempStr = objSelect.options[objSelect.selectedIndex].value;
arVal = tempStr.split("|");
oID = arVal[0];
label = arVal[1];
//alert(tempStr+"\\n"+oID+"\\n"+label);
if(!oID || !label)
alert("Please select a valid link to insert.");
else
insertHTML('<a href="#application.url.conjurer#?objectid='+oID+'">'+label+'</a>');
return false;
}
</script>
<div class="relateditems-wrap" style="margin-left:30px;">
<h2>Links</h2>
<select name="links" id="links" size="3">
<cfloop from="1" to="#getHTMLPages.recordcount#" step="1" index="i">
<option value="#getHTMLPages.objectid[i]#|#getHTMLPages.label[i]#">#getHTMLPages.label[i]#</option>
</cfloop>
</select>
<div class="f-submit-wrap">
<input type="button" name="buttonInsertLinkInBody" value="Insert in body" class="f-submit" onclick="return getLinkValueInsert();" />
</div>
</div>
</cfoutput>
At the top of your body.cfm file inside _dmHTML/plpEdit/ add the following line towards the top:
<cfimport taglib="/farcry/designer/tags/widgets" prefix="cWidgets">
cWidgets stands for custom widgets. You can now call this using the following:
<cWidgets:bodyInsertLink>
Why is this better you ask? Because I said so! That and the fact that by creating this as a widget you can extend any content type (ie. News, events, and more importantly custom types) and use this there as well.

Related Articles
No user responded in this post
Leave A Reply