how to add a # in cfoutput? - html

I have to render the following html tags from an ajax query. Issue is cfml treats any string prefixed with # as an identifier. So I'm getting an error.
<cfoutput>
<table style="display:none;" width="100%" border="1" cellpadding="2" cellspacing="0">
<tr>
<td width="43%" bgcolor="#649DCA"><strong>Class</strong></td>
<td width="20%" bgcolor="#649DCA"><strong>Site</strong></td>
<td width="47%" bgcolor="#649DCA"><strong>Date/Time</strong></td>
</tr>
</cfoutput>

You just need to double up your #'s.
<td width="43%" bgcolor="##649DCA"><strong>Class</strong></td>
Personally, I would probably just use CSS and style the table separately.

Related

Nested variables not rendering in email template using mustache

So I am having trouble getting the variable values to be shown in an email template. The 3rd party email templating provider is Postmark and it uses Mustache. My template is set up like this (I have ommitted some of the irrelevant html to keep things shorter):
{{#discount_group.delivery_fee}}
<tr>
<td width="30%" class="purchase_footer" valign="middle">
<p class="purchase_total">{{delivery_fee}}</p>
</td>
</tr>
{{/discount_group.delivery_fee}}
{{#discount_group.discount}}
<tr>
<td width="30%" class="purchase_footer" valign="middle">
<p class="purchase_total">{{discount}}</p>
</td>
</tr>
<tr>
<td width="30%" class="purchase_footer" valign="middle">
<p class="purchase_total_bold">{{grandtotal}}</p>
</td>
</tr>
{{/discount_group.discount}}
And my json payload looks like this:
"discount_group": {
"delivery_fee":"delivery_fee_Value",
"discount": "discount_Value",
"grandtotal": "grandtotal_Value"
}
But when I send out the email, the sections render properly but the variable values are blank (red box):
If I remove "delivery_fee" from the json payload, the section is not rendered as expected but the values are sill missing:
I have also tried {{discount_group.delivery_fee}} and {discount_group.discount}} etc but that still had the missing values.
What am I doing wrong?
Thanks in advance
So I figured it out. I'm not sure why it has to be this way but it does. My problem was in the payload. The payload should be formatted like this:
"discount_group": {
"delivery_fee":{
"delivery_fee":"delivery_fee_Value"
},
"discount": {
"discount":"discount_Value",
"grandtotal": "grandtotal_Value"
}
}
When you wrap a block of code in mustache, what you're doing is stepping into that object in your data in an effort to make your code more readable. Postmarks documentation calls it 'Scoping'. You can read up on here!
Therefore, by starting blocks with, for example, {{#discount_group.delivery_fee}}, you are already at delivery_fee and calling it again will return nothing since it doesn't exist.
With how your data was originally structured, you had everything you needed nested in discount_group, so you didn't need to nest further in your brackets. I know you have found a resolve, but in the future, instead of changing your data to match your code, you could consider instead update your code to be as follows:
{{#discount_group}}
<tr>
<td width="30%" class="purchase_footer" valign="middle">
<p class="purchase_total">{{delivery_fee}}</p>
</td>
</tr>
<tr>
<td width="30%" class="purchase_footer" valign="middle">
<p class="purchase_total">{{discount}}</p>
</td>
</tr>
<tr>
<td width="30%" class="purchase_footer" valign="middle">
<p class="purchase_total_bold">{{grandtotal}}</p>
</td>
</tr>
{{/discount_group}}

Hide/show 2 table rows when having data

I need to display 2 empty table row when don't have any data and when they do have data those 2 empty table rows should be hidden. Now i can write the code for display data in the table rows but it doesn't display 2 empty table rows when it doesn't have data, so please help me to solve this problem. thank you.
<table class="message_table" width="1025" border="0" cellspacing="1" cellpadding="5" align="center" bgcolor="#c9c9c9">
<tr style="background-color:#797a7b;">
<td style="color:#fff;">序号</td>
<td style="color:#fff;">模式</td>
<td style="color:#fff;">时时彩返点</td>
<td style="color:#fff;">11选5返点</td>
<td style="color:#fff;">低频返点</td>
<td style="color:#fff;">操作</td>
</tr>
<a4j:repeat value="#{AgentAutoRegBean.reslist}" var="list"
id="dblist" rowKeyVar="keys">
<tr style="background:#{keys%2==1?'#EEEEDD':'#f4f4f4'}">
<td>#{keys+1}</td>
<td>#{list.model}</td>
<td>
<h:outputText value="#{list.pointssc}" converter="PercentConverter"/>
</td>
<td>
<h:outputText value="#{list.point115}" converter="PercentConverter"/>
</td>
<td>
<h:outputText value="#{list.pointdp}" converter="PercentConverter"/>
</td>
<td>
<font color="#5a5a5a">
<a4j:commandLink value="编辑" status="normalStatus" action="#{AgentAutoRegBean.edit}" data="#{AgentAutoRegBean.msg}" oncomplete="edit01(data)">
<f:param name="sign" value="#{list.sign}"/>
</a4j:commandLink>
<rich:spacer width="8"></rich:spacer>
<a4j:commandLink value="网址" onclick="winopen('#{list.sign}');return false;">
</a4j:commandLink>
</font>
</td>
</tr>
</a4j:repeat>
</table>
If you want to fill it later you have to use the var attribute of the a4j:repeat and prepare a list with 2 (empty) elements in the backing bean before access the data and use listeners for fill the list later.

Rails 3 string contains HTML code need to loop through the code in string

I am working on the rails 3 application where i need to pass the html code in to the string variable and pass it to the web services as parameter.
I have the following code with the loop inside but since it is declare in to the string it is not working with the <%%> and #{} tag
#emaildata = "<H3>FLOOR VIEW ACTION REQUEST</H3>
<table border='0' cellspacing='4'>
<tr>
<td>Submitted On:</td>
<td align='left'><strong>#{Date.today}</strong></td>
</tr>
<tr>
<td> Originator: </td>
<td align='left'><strong>#{session[:user_name]}</strong></td>
</tr>
</table>
<table border=0 width=100%>
<tr bgcolor='##006699'>
<td align='center'><font color='##FFFFFF'><strong>ACTION CODE</strong></font></td>
<td align='center'><font color='##FFFFFF'><strong>PART<BR />NUMBER</strong></font></td>
<td align='center'><font color='##FFFFFF'><strong>LOCATION</strong></font></td>
<td align='center'><font color='##FFFFFF'><strong>BIN QTY</strong></font></td>
<td align='center'><font color='##FFFFFF'><strong>PACK QTY</strong></font></td>
<td align='center'><font color='##FFFFFF'><strong>UM</strong></font></td>
<td align='center'><font color='##FFFFFF'><strong>SCAN CODE</strong></font></td>
<td align='center'><font color='##FFFFFF'><strong>REASON / COMMENTS</strong></font></td>
</tr>
<% (1..PartNoListInEmail.length).each_index do |i|%>
<tr bgcolor='##E0E5E5'>
<td align='center'>#{#ActionCodeListInEmail[i]}</td>
<td align='center'>#{#PartNoListInEmail[i]}</td>
<td align='center'>#{#SendToListInEmail[i]}</td>
<td align='center'>#{#OrderQtyListInEmail[i]}</td>
<td align='center'>#{#PackQtyListInEmail[i]}</td>
<td align='center'>#{#UMListInEmail[i]}</td>
<td align='center'>#{#ScancodeListInEmail[i]}</td>
<td align='center'>#{#reasonForActionIn[i]}</td>
</tr>
<%end%>
</table>"
Please help me .
Save your html as partial as a html.erb
#emaildata = "<%= escape_javascript(render :partial=>'some_partial_name', :locals => {:PartNoListInEmail => #PartNoListInEmail}).html_safe %>"
For combining strings with HTML, you want to use a template system like Erb or Haml. If you don't intend to immediately render the template back to a browser, you can still use Erb to do this by calling Erb directly, having it parse the HTML string and variables and return the result as a string.
Once you go down this road, be extra careful of user provided content and escape anything untrustworthy. When you render erb templates normally in rails, rails does a fair amount of work for you to avoid these sorts of problems, but once you do something like what your example showed, or if you use Erb directly to parse it, you no longer benefit from Rails' safety checks, and therefore will need to put in your own checks.

dont want to submit form when one of fields value is wrong or left empty

I am using Struts framework in my web application, i am facing problem in my coding when i click on radiobutton doctor hmm it asks for docid and so profile will be updated but if user doesnt give id and select doctor and save profile , menus of patient changes to doctor and user becomes doctor due to getter setter in beans have these values just update function doesnt works ..and same for pathologist..
<html:form action="upAction" enctype="multipart/form-data">
<table>
<tr class="show" id="admhide">
<td align="left" valign="middle" nowrap><bean:message key="sp.type"/></td>
<td align="left" nowrap><html:radio property="type" value="Patient" name="reg" styleId="patradio" onclick="show(this.value);"/>Patient
<html:radio property="type" value="Doctor" name="reg" styleId="docradio" onclick="show(this.value);"/>Doctor
<html:radio property="type" value="Pathologist" name="reg" styleId="pathradio" onclick="show(this.value);"/>Pathologist</td>
</tr>
<tr class="hide" id="doctor">
<td align="left" valign="middle" nowrap><bean:message key="sp.docid"/></td>
<td nowrap align="left" ><html:text property="docid" name="reg" styleId="docid"/></td>
</tr>
<tr class="hide" id="patho">
<td align="left" valign="middle" nowrap><bean:message key="sp.pathoid"/></td>
<td nowrap align="left" ><html:text property="pid" name="reg" styleId="pathid"/></td>
</tr>
<tr>
<td colspan="2" align="center" valign="middle" nowrap><html:submit styleClass="button2" property="method"><bean:message key="userform.upd"/></html:submit></td>
</tr>
</table>
</html:form>
please help me how to do this so that if user fills wrong docid or no docid form dont sets rest values in getter setters and doesnt gets submit .. thankyou ..
I think you need to apply JavaScript checks for Empty fields.
go to this link for understanding Javascript Validations :
http://www.w3schools.com/js/js_form_validation.asp
For a wrong Doc Id, when the form is submitted you need to check the Doc Id first in your code before saving other details otherwise return the same page with errors like "wrong docid".

Using ruby and nokogiri to parsing HTML using HTML comments as markers

How could I use ruby to extract information from a table consisting of these rows? Is it possible to detect the comments using nokogiri?
<!-- Begin Topic Entry 4134 -->
<tr>
<td align="center" class="row2"><image src='style_images/ip.boardpr/f_norm.gif' border='0' alt='New Posts' /></td>
<td align="center" width="3%" class="row1"> </td>
<td class="row2">
<table class='ipbtable' cellspacing="0">
<tr>
<td valign="middle"><alink href='http://www.xxx.com/index.php?showtopic=4134&view=getnewpost'><image src='style_images/ip.boardpr/newpost.gif' border='0' alt='Goto last unread' title='Goto last unread' hspace=2></a></td>
<td width="100%">
<div style='float:right'></div>
<div> <alink href="http://www.xxx.com/index.php?showtopic=4134&hl=">EXTRACT LINK 1</a> </div>
</td>
</tr>
</table>
<span class="desc">EXTRACT DESCRIPTION</span>
</td>
<td class="row2" width="15%"><span class="forumdesc"><alink href="http://www.xxx.com/index.php?showforum=19" title="Living">EXTRACT LINK 2</a></span></td>
<td align="center" class="row1" width='10%'><alink href='http://www.xxx.com/index.php?showuser=1642'>Mr P</a></td>
<td align="center" class="row2"><alink href="javascript:who_posted(4134);">1</a></td>
<td align="center" class="row1">46</td>
<td class="row1"><span class="desc">Today, 12:04 AM<br /><alink href="http://www.xxx.com/index.php?showtopic=4134&view=getlastpost">Last post by:</a> <b><alink href='http://www.xxx.com/index.php?showuser=1649'>underft</a></b></span></td>
</tr>
<!-- End Topic Entry 4134 -->
-->
Try to use xpath instead:
html_doc = Nokogiri::HTML("<html><body><!-- Begin Topic Entry 4134 --></body></html>")
html_doc.xpath('//comment()')
You could implement a Nokogiri SAX Parser. This is done faster than it might seem at first sight. You get events for Elements, Attributes and Comments.
Within your parser, your should rememeber the state, like #currently_interested = true to know which parts to rememeber and which not.