How to render fields in Sitecore MVC - Partial View - sitecore

How can i render a field or image from template in my Partial View. I need to edit content by the Page Editor.

There are a couple of ways to do this but at the most basic level, you can render a field in your partial view by using the following syntax:
#Html.Sitecore().Field("myFieldName")
I recommend checking out John West's blog for more MVC-related tips: http://www.sitecore.net/Community/Technical-Blogs/John-West-Sitecore-Blog/Posts/2012/06/Posts-about-Using-MVC-with-the-Sitecore-ASPNET-CMS.aspx
There is also documentation on Sitecore's SDN site: http://sdn.sitecore.net/Reference/Sitecore%206/MVC%20Reference.aspx

Access the value of your Field By using FieldRenderer.Render and Render it in the View #Html.Raw(Model.Urfieldname). This will work.
Thanks

Related

Use template tag (in HTML ) in view as a variable

I'm creating a web page on Django,
I want to create next and previous post in the bottom of blog page.
is there any way to use a simple tag like {{post.title}} in HTML and refer it to view page to find the index of current post ?
This is where you should use pagination. If you are using DRF you might need this pagination.

Illustrated texts in Django model

I am trying to make one Blog using Django 2.0 and I have already created a primitive one. It has a Post model which is as follows:
class Post(models.Model):
PriKey = models.CharField(max_length=255,primary_key=True)
Heading = models.CharField(max_length=100)
DateOfPost = models.DateField(default=datetime.date.today())
Content = models.TextField()
As it can be seen, the content area is only textual and as of now, I can't add any special style or pictures inside my content.
I thought of using HTML tags inside the text content but they are appearing unchanged when the web page is rendered.
So my question is, is there any way of storing pictures along with the text in the content field of the Post model? I want to make something like this
Is there any way of showing the pictures in their respective positions using Django model? If no, is there any other way of doing this?
Also, is there any way of storing HTML codes inside django models and render them as it is when the website is run?
You can store html tags inside the field.
while rendering, to template mark it as safe
{{ post.content|safe }}
This will render all the html tags.
But this is not a good way as it makes you vullerable to cross site scripting attacks
A better method is to use something like a ckeditor
It provides a RichTextField and RichTextUploading Field and using this you can upload pictures, videos, code snippets, style your text and a lot more inside one field.
There are many other optons, but I prefer ckeditor
Ckeditor is a cross platform editor, django-ckeditor is a library containing django implementation of ckeditor which gives you full backend and frontend combined
ckeditor
django-ckeditor
django-pagedown A django app that allows the easy addition of Stack Overflow's "PageDown" markdown editor to a django form field, whether in a custom app or the Django Admin
I think you should give it a try
Cheers :)

Django enable URL link in template

I have a blog and users can comment any articles. For now, when they post an URL, we can not follow the link by a clic. Because there is no tag.
I know we can display HTML by using the filter "|safe". But I don't want a user using all html tag for security reasons.
I just want to make URL like "http://google.fr" as active and cliquable.
Any idea ?
The urlize filter does exactly what you want.

EmberJS - How to display subset of a model in a view

I am very new (started today) to Ember and cannot figure how how to set this up in a correct manner.
Models:
Post, Comment
On the 'show' template for Post, I want to display only the comments that are not blocked (isBlocked is a attribute of Comment model). Should I use a View and pass in a param to filter out the comments?
I cannot find an useful example or tutorial that explains this. Is there a way similar to how this would be done in Rails with partials and locals or something?
You can use a computed property that uses filterProperty to filter your model inside your controller. Then use that computed property to display in your template.
Assuming your Comment model has an isBlocked attribute, you can set up a computed property like,
comments: function() {
return this.filterProperty('isBlocked', false);
}.property('#each.isBlocked')
Then in the template use comments as the collection to iterate over. The comments collection will have all comments except those where isBlocked is true.

Django: Pagination with urls.py

I'm building a Blog in Django (using Generic Views) and I use the same template for both my date based and list detail views. I'm trying to setup pagination, but I want to do so with URL patterns rather than using an ugly ?page=1 url suffix.
The problem is in the actual html template, I cannot find a way to determine which view was used to render the page, so while I have access to all the pagination stuff, I have no way to generate the appropriate URL.
In other words, if the view was rendered by my archive_month(request, month, year, page=0) view, I would need to structure the URL for the next and previous pages as /blog/dec/2009/PageX/, versus the blog index, which would mean the URL would be /blog/pageX/.
Well I just realized that date_based generic views don't support pagination, so problem solved.