publish html content with script in it

Topics: General
Mar 4, 2012 at 6:14 PM

First of all I am a beginner

can I publish html content with script in it

for example I want to  publish article (blog post) and I use jquery  Dom Manipulation to generate footnote and table of contents

can I implemnt this in orchard? 

Developer
Mar 4, 2012 at 6:17 PM

I don't see why not; did you try it?

Mar 4, 2012 at 6:55 PM

this is my html which part to add to orchard in html editor in order to work

 

<html>                                                                 
<head>
<link rel="stylesheet" href="mystyles.css" type="text/css" />
                                                         
<script type="text/javascript" src="jquery-1.7.1.min.js"></script>    
<script type="text/javascript">                                        
// we will add our javascript code here   
    
$(document).ready(function() {
$('<a href="#top">Up</a>').insertAfter('div.chapter p');
$('<a id="top"></a>').prependTo('body');
});
  </script>                                                     
</head>                                                                                                                          
<div class="chapter" align="justify" >
<p>
paragraph 1
</p>
<p>
paragraph 1
</p>

</div>
                   
</body>                                                                
</html>

Developer
Mar 4, 2012 at 7:02 PM

That would be this part:

<script type="text/javascript">                                         
// we will add our javascript code here    
     
$(document).ready(function() {
$('<a href="#top">Up</a>').insertAfter('div.chapter p');
$('<a id="top"></a>').prependTo('body');
});
  </script>                                                      

 

Mar 4, 2012 at 7:11 PM

this is the steps I follow

Dashboard>Blog>New Post>

int the body if I click Html it will open the Html editor

if I add the scrit only as I understand from you

what about the body of my post

<div class="chapter" align="justify" >
<p>
paragraph 1
</p>
<p>
paragraph 1
</p>
</div>

there is somehting that i didn't understand

 

 

Developer
Mar 4, 2012 at 7:20 PM
Edited Mar 4, 2012 at 7:20 PM

The complete HTML body of your post would be something like this:

<div class="chapter" align="justify" >
<p>
paragraph 1
</p>
<p>
paragraph 1
</p>
</div>

<script type="text/javascript">                                         
// we will add our javascript code here    
     
$(document).ready(function() {
$('<a href="#top">Up</a>').insertAfter('div.chapter p');
$('<a id="top"></a>').prependTo('body');
});
  </script>   

This will effectively insert a hyperlink with the text "Up" just below the content of your post.

However, might I suggest that you should not mix script with content.
Instead, what you would want to do is override the template of the blog post, in which you insert the link to the anchor at the top (you should even omit the script entirely, as it doesn't do anything that you couldn't do with plain HTML).

Also, in your Layout.cshtml, add the anchor with id "top", so that the link in your blog post template will work.

Doing that will have at least 3 benefits:

  1. No repetition of scripts in each and every blog post
  2. No scripts mixed with content
  3. No javascript required

 

Mar 4, 2012 at 8:07 PM

It is not simple as I thought but it make me unhappy

I will not only generate Link to top

I also will generate footnote,table of contents ,Paragraph number, Auto link to other blog post, and I think in using jQuery to format the blog post

I thinks there should be another way to do it, or another way of thinking of preparing my blog that will be posted

may another one have a better Idea??

 

 

 

Developer
Mar 4, 2012 at 8:15 PM
Edited Mar 4, 2012 at 8:16 PM

Well, your initial question was whether or not it would be possible to publish both content as well as script, which is possible and is quite simple as you have seen.

However, the things you mention require a bit more effort than just pasting scripts along with your blog posts. I think you won't be able to do it without overriding some of the templates (which isn't that hard, especially using the Shape Tacing tool).

But perhaps I'm missing your point and I'm overthinking it.