how to display a variable that contain html template in smarty?
$smarty = new my_smarty();
$page_content = "<p>{$my_content}</p>";
$smary->assign("my_content","whatever...");
$smarty->display($page_content); // how to render $page_content ???
From the documentation:
Smarty can render templates from a string by using the string: or eval: resource.
The string: resource behaves much the same as a template file. The template source is compiled from a string and stores the compiled template code for later reuse. [...]
The eval: resource evaluates the template source every time a page is rendered. [...]
For your case:
$smarty = new my_smarty();
$page_content = "<p>{$my_content}</p>";
$smary->assign("my_content","whatever...");
$smarty->display("string:" . $page_content);
Related
ESRI's JS API seems to be stripping out the hrefs of URLs.
Here I set up a static link. Then I attempt to put it in the description. The link text and target="blank" are rendered but the link's href (test/) is blank!
{% for project in projects %}
var link = "<a target='blank' href='test'>Legal Description</a>";
console.log(link) // This prints as expected with href intact.
var attributes = {
Name: "{{project.description}}",
Description: link // strips out the href?!?!?!?!
}
It SHOULD be localhost:8000/projects/test but there is no test href.
The arcgis-js-api sanitizes html content in popups for security reasons. I'm not sure how you're defining your popups or using the attributes variable, but you'll want to create a PopupTemplate, and its its content property to do what you want. You can do it like the linked article recommends, or you can use a CustomContent instance for the popupTemplate content property.
Is it possible to turn a String into a Hyperlink using Html.Raw. What would the code for this be?
I'm trying to embed an <a> Tag into a Razor Page with the following:
#{
string strText = "<title>Link Test</title><a class=\"nav-link text-dark\" target=\"_new\" asp-
area=\"Test\" asp-controller=\"Test\" asp-action=\"ViewFile\" asp-route-Id=1> View File Test</a>";
}
#Html.Raw(strText)
My page just shows "View File Test" without a link.
When I view the page source in my browser I see the following:
<title>Link Test</title><a class="nav-link text-dark" target="_new" asp-area="Test" asp-controller="Test" asp-action="ViewFile" asp-route-Id=1> View File Test</a>
When I copy the above and paste it to my razor page, all works well.
Just for fun, I have also tried the following and get the same result:
#{
string strText = "<title>Link Test</title><a class=\"nav-link text-dark\" target=\"_new\" asp-
area=\"Test\" asp-controller=\"Test\" asp-action=\"ViewFile\" asp-route-Id=1> View File Test</a>";
}
<text>#strText</text>
The following example below works fine, but not the above. I thought maybe it had to do with the embedded quotes
#{
string strText = "My Text My link.";
}
#Html.Raw(strText)
For HtmlHelper.Raw Method , the parameter is the HTML markup, however asp-area and asp-controller are the Anchor Tag Helper attributes. HTML code, or actually any text, returned from methods is not processed by the Razor engine, so you cannot use HTML tag helpers here.
You could try to use #Html.ActionLink or #Url.Action helper methods as shown:
#{
string strText = "<title>Link Test</title><a class=\"nav-link text-dark\" target=\"_new\" href=\""+Url.Action("ViewFile","Test" ,new { Area="Test",Id=1})+"\" >View File Test</a>";
}
the generated url will be https://localhost:44348/Test/Test/ViewFile?Id=1.
register routes as below:
app.UseEndpoints(endpoints =>
{
endpoints.MapControllerRoute(
name: "areaRoute",
// if you don't have such an area named as `areaName` already,
// don't make the part of `{area}` optional by `{area:exists}`
pattern: "{area}/{controller=Home}/{action=Index}");
endpoints.MapControllerRoute(
name: "default",
pattern: "{controller=Home}/{action=Index}/{id?}");
});
Reference:
https://stackoverflow.com/a/35579040/10201850
https://stackoverflow.com/a/53147778/10201850
The main reason your solution with asp tags will not work because they (tag helpers) are compiled at run time into your existing views.
At runtime compilation, your string is getting compiled as a string and tags inside that are being ignored obviously because compiler is unaware of them.
But when you use html attributes like anchor tag, it will work fine because that gets parsed by your browser.
Keep in mind that in Razor, asp- prefixed attributes for tags are somehow rendered at server side. This properties/attributes are not from HTML5.
Answer: Yes, it is possible, but it must be valid HTML.
Being new to TYPO3 fluid I was wondering if there's an easy way to create a link to a PDF-file which is located in the filelist as you would in simple html as follows:
Click here to open pdf (in a new window)
I couldn't find a solution so far that wouldn't require an extension or that wouldn't render the pdf direclty on the page (<flux:field.inline.fal name="settings.image" required="1" maxItems="1" minItems="1"/>)
Should/Can this be done with <f:link.external href="filePathOnServer/file.pdf"> ? (I've got another problem at the moment preventing me from checking if this works...)
EDIT
I've tried using <f:link.external> which didn't work. For the time being I'm using the (non-fluid) <a>-tag...
I had to do the same thing and I resolved it by writing a custom ViewHelper just to get the site url.
ViewHelper:
class InternalViewHelper extends AbstractViewHelper
{
/**
* Renders a link to a specific path from the root path of TYPO3.
*
* #param string $path The path to an internal resource relative to the TYPO3 site URL.
* #return string The absolute URL to the given resource.
*/
public function render($path)
{
$siteUrl = GeneralUtility::getIndpEnv('TYPO3_SITE_URL');
return htmlspecialchars($siteUrl . $path);
}
}
Fluid Template:
{namespace ext = Vendor\MyExt\ViewHelpers}
<f:link.external target="_blank"
uri="{ext:internal(path: 'uploads/tx_myext/myfile.pdf')}">
Link
</f:link.external>
I have a form that needs to submit a .csv file to the server and then append the words in it to a textarea in my page. I am using Remotipart to upload the .csv using AJAX but I cannot get the javascript in the server response to execute. Here are the relevant parts of my code:
The Form:
=form_tag(upload_canvas_words_admin_page_widget_widget_instance_path(widget.page, widget),:method=>'post',:remote=>true,:multipart=>true,:class=>"upload_words_csv") do
= label_tag "Upload File"
= file_field_tag "file"
= submit_tag "Upload"
The Controller:
def upload_canvas_words
#csv_text = params[:file].read
end
The .js.haml file:
= remotipart_response do
- if remotipart_submitted?
alert('#{#csv_text}');
alert('!');
- else
alert('WHYYYYY?');
When I look at the response I see the javascript being wrapped in a bunch of html, which I assume has something to do with the iFrame transport. But the javascript never actually executes.
Refer this issue. And try to follow the solution given here.
https://github.com/JangoSteve/remotipart/issues/89
So what happens is that reponse arrives to the browser with html entity (like ") inside the textarea. When the js code for evaluation is extracted the html entities are replaced by theirs respective characters (like " to ').
That's a characteristic of a textarea. So it doesn't get executed
Adding data: {type: :script} to the form should be the fix
This may be a sad implementation to start with but...
I have an XML string that I want to pass to a FusionChart but it fails (without errors...).
Controller code: trying to pull XML from a page
data_url = "[removed URL]/run/custom.xml?start=#{#start_week}&end=#{#end_week}&x=daychart=line&application=#{#application}".html_safe
data_uri = URI::escape(data_url)
#response = RestClient.get(data_uri)
Rails.logger.debug("Data: " + #response.inspect)
View Code: instantiating the Chart and passing the XML
<script>
var chart = new FusionCharts("/charts/MSLine.swf", "quality_center_stats", "700", "400", "1", "0");
chart.setDataXML("<%= #response %>");
chart.render("quality_center_stats");
</script>
Let me know if there is more I can add
Can be any of the following:
The XML contains special characters which needs to be encoded in the DataXML method. e.g., % should be passed as %25, & as %26, " as %26quot; or "
Make sure you do not have any newline character in that XML string. That would break the string in JavaScript (and you will get "unterminated string" error in JavaScript console)
Make sure the XML data which is passed conforms to FusionCharts Mulit-series data format
Make sure you have placed the SWF and JS files in proper paths and are accessed correctly. (can check through network tab of Firebug or Developer Console of Chrome)