I want to display predefined HTML in a variable - codeigniter

I am using Codeigniter and everything works just fine. I can assign PHP variable to smarty an display them.
But now I am calling a webservice and this webservice returns a complete HTML (and javascript) page.
I want to display this in a smarty template.
So I have done the following:
I have assigned the output of the webservice to a PHP variable and assigned this to a smarty variable (HTMLstring), like I always do. That part works.
In my smarty template I don't need anything but to display the contents of the variable. So my template contains just one line:
{HTMLstring}
But this displays the literal HTML including tags and all. I want to display the output.
(If I copy-paste the output in a separate html file, and open that, it just looks fine)

I 'figured out' the answer.
It appears it makes a difference if I call the template from code or just type the complete url in my browser for testing purposes. The latter didn't work, the former does. I still don't know why. Sorry...
Question closed.

Related

How can I get a property of an HTML element using Bash?

I'm trying to get the propierty of an HTML value using Bash. It's a personal project so I can use cURL, wget, everything, but needs to be bash.
Suppose I want to scrape Google to get the value of the jscontroller property that appears in the first div inside the body
Basically, how can I do it?

CKEditor with HTML content stores, displays but cannot display for edit

I have used CKEditor for a few years without really understanding it. I now want to use it to display text which will include HTML, CSS, JavaScript and PHP example code. None of that needs to execute it is just to show the code to others.
Currently I used the textarea replace method to edit content and I need to carry on that way. When I add the content first time it is sanitised (mysqli_real_escape_string) and stored in a MySQL database correctly. It also then displays correctly with the CKEditor markup working as markup and the HTML/PHP showing as a code example. However, when I edit the content a second time the HTML examples become "real" HTML and are no longer visible as examples.
For example this:
<?php echo "hello"; ?>
<p>Hello</p>
is correctly (?) stored as:
<p><?php echo "me"; ?></p>
<p><p>Hello</p></p>
and displays on the page as shown in the first code snippet (which is what I want). When I then hit edit again the code examples vanish into the background as real HTML (part of the page). If I put the code examples in as code snippets (which I would rather not have to do because of the intended users) the result in the editor (second edit) looks like this:
<!--?php echo "me"; ?-->
Hello
I am sure i am missing a basic understanding of what is going on behind the scenes but can anyone explain how to allow users to type in text which includes HTML, CSS, JavaScript, PHP and MySQL code examples which must then appear as examples and not markup (and be editable as examples).
I have played with config.entities and config.protectedSource after some research but they do not seem to be relevant (or to work). Weirdly a couple of times it seemed to work fine and I thought I had cracked it but then stopped with no further changes to the config. That means I now have less idea what I am doing than when I started!
You don't mention which version you are using, but if it's relatively new (4.4+) you can use the Code Snippets plugin that was designed exactly for this. See the demo at http://ckeditor.com/demo#widgets. It might help with the encoding issues too. There's docs on it too.
Th help with the current encoding issue, it would help a LOT if you showed us how you output the data and load it into CKEditor. For example "When I then hit edit again" doesn't really describe anything without context. For example, do you use setData() with AJAX? Do you use an inline editor? Code examples would be the best.

Knockout set initial value of an input field where html is allowed

I have two input fields first name and last name.
Application was running really well.
Suddenly someone came in from Mars and input something like this in those input fields
*(~'##~>?<+!""*%$)!
for both first name and last name. Now don't ask me why he did this cause in Mars this is very common. You can try it on this fiddle
http://jsfiddle.net/farrukhsubhani/3RjRF/
This text then went into my database and now when i retrieve it it came back like this
*(~'##~>?<+!""*%$)
which is ok for me as its html and I can place it back into knockout and it gets populated as html as you can see in fiddle above. However this Mars guy then thought that on Earth this is not a nice name to be with so he tried to edit field.
The above fiddle is kind of that edit page which shows him old value at bottom and two fields at top. He does not know html so he thought we have changed his name in input fields however I need to know
When passing text to knockout to give initial value to an input field is it possible to tell it that consider this text as html so it renders properly in input field
The other way around is to send him to http://www.w3schools.com/tags/ref_entities.asp and tell him about reserved HTML characters. This info has been stored in database (using Entity Framework simple person.fname and person.lname both with attribute AllowHTML) so on my fiddle i have just placed it in two variables and you can see how actual text boxes are different than html below. If i dont bind using Knockout then actual text is shown in these boxes and user can edit <>' signs without any problem.
Anyone with a solution before he leaves our planet. This can change alien life on our planet.
Update
If i go into this field and paste (~'##~>?<+!""*%$)" binding works fine and you can copy this and paste it into fiddle to see that. However its not taking that value from Javascript variable to knockout expects it to be a string and html special characters are not shown properly in input field.
We have done another test without Knockout and this text does get rendered within the field when you try to edit it its fine.
We have updated JSfiddle to work without JQuery and its the same result if you store it in a js variable and give not value to input field
http://jsfiddle.net/farrukhsubhani/3RjRF/3/
If we assign value to input field and just use jQuery to populate fullname then it works
http://jsfiddle.net/farrukhsubhani/3RjRF/4/
This last fiddle is a working example and we want Knockout to do what JQuery is doing.
I think the question then comes to how can this text be stored in javascript variable and placed into input field as html text so special characters appear unescaped. You can try unescape on jsfiddle that did not work for us.
Somewhere along the trip into (or maybe out of) your database, the value is being HTML-escaped. It's not Knockout itself that's doing it. You're going to need to track that location down, but you can't just disable it; you're going to have to replace it with something that sanitizes the result or otherwise you're opening yourself up to cross-site scripting attacks (any <script>s from external sources inserted into the input would have complete access to your data).
Any time you see the html: binding used, warning bells should go off in your head and you should VERY carefully to check to ensure that there's NO possibility of raw, unexamined user input making it into the string that gets displayed.
Ok here is what i did at the end
http://jsfiddle.net/farrukhsubhani/3RjRF/7/
I have done following:
I have added value attribute to input field and placed the input text as it came from server into it. Because I am using TextBoxFor in MVC it did that for me.
Before I apply knockout binding I have picked this value up using $('#kfname') and passed it to the actual binding so it used the value that came from server. Previously it was passed like (#Model.fname,#Model.lname)
I think what this did was allowed jQuery to pick up the value and assign it to binding instead of variable
ko.applyBindings(new ViewModel($("#kfname").val(), $("#klname").val()));
Hopefully this would help someone using knockout.

regarding image downloading function

Can anyone help me to solve my issue regarding the image downloading function? The situation goes like this: actually I wanna download a gantt chart image from a site that generates some string url as the image! not even http://www.example.com/img/image.png but something like http://www.example.com/img/index.php?=task&d=&Work=0...
Disregarding what language or environment you are working in, simply using the full URL with all the GET variables in place will provide you with the image.
It should not matter.
Judging from your comments below, your code is not working because you are using PHP's htmlspecialchars function.
Htmlspecialchars will turn symbols that you cannot represent in HTML output simply by adding them to the source of an html document (such as &, < and >) into identifiers that will let the browser know what kind of character to render.
for instance the ampersand (&) could be rendered by & the HtmlSpecialChars function does this for you.
When your backend code is outputting parts of html source that aren't visible to the user, such as the source of an image in this case, you do not want to use that function.
It will invalidate the URL by replacing all the & instances in the url by &
Simply do this:
<?php print($url); ?>

Setting access to remote in a cffunction includes the application.cfm page

When I set a cffunction's access to remote--so I can call it through AJAX--the call returns the HTML I have in my Application.cfm template.
Is there any way around this, or do I have to move the HTML out of Application.cfm?
This would be considered expected behavior. I'd suggest not outputting content within your Application.cfm. Consider using custom tags for wrapping your pages or better yet switch to using Application.cfc and use custom tags.

Resources