EpiServer: get content in the currently selected language? - episerver

We have a block that pulls in content and displays it on our page. Right now, no matter what language I select in our language switcher, this is not being honored by our block.
As I am new to EpiServer and C# I think I have identified the following line of code as being the one that pulls in the data?
ServiceLocator.Current.GetInstance<IContentLoader>();
Can I rewrite this to only get content in the language that is currently selected by the user?
I am unsure how to combine it with the CultureInfo class.

You can try something like this:
IContentLoader contentLoader = ServiceLocator.Current.GetInstance<IContentLoader>();
PageData page = contentLoader.Get<PageData>(new ContentReference(1234) /*Your contentreferenceid to fetch ere*/, ContentLanguage.PreferredCulture);

Related

Different Case's Created Date fieldApiName for Case's list view

I have custom logic to create lisview with filters for any object in SF using metadata api. I noticed when I try to upadate All Opened Cases listview and add filter logic "CreatedDate equals TODAY" (put CASES.CREATED_DATE_DATE_ONLY api name for metadataapi) it's saved. But after refreshing listview getListInfoByName wire returned label = null and fieldApiName = null in filter object(listview is crushed). If I create the same filter and update listview (put CASES.CREATED_DATE api name for metadataapi) it works fine and getListInfoByName wire is not crushed. In another sanboxes it works fine with CASES.CREATED_DATE_DATE_ONLY instead of CASES.CREATED_DATE. So my question is what is the diffrence between sandboxes (some enabled features and etc.)? All sanboxes works fine with CASES.CREATED_DATE_DATE_ONLY and one only needs CASES.CREATED_DATE. Thanks.
I need understand the difference between my sanboxes or smth like that

SuiteCommerce Advanced - Show a custom record on the PDP

I am looking to create a feature whereby a User can download any available documents related to the item from a tab on the PDP.
So far I have created a custom record called Documentation (customrecord_documentation) containing the following fields:
Related item : custrecord_documentation_related_item
Type : custrecord_documentation_type
Document : custrecord_documentation_document
Description : custrecord_documentation_description
Related Item ID : custrecord_documentation_related_item_id
The functionality works fine on the backend of NetSuite where I can assign documents to an Inventory item. The stumbling block is trying to fetch the data to the front end of the SCA webstore.
Any help on the above would be much appreciated.
I've come at this a number of ways.
One way is to create a Suitelet that returns JSON of the document names and urls. The urls can be the real Netsuite urls or they can be the urls of your suitelet where you set up the suitelet to return the doc when accessed with action=doc&id=_docid_ query params.
Add a target <div id="relatedDocs"></div> to the item_details.tpl
In your ItemDetailsView's init_Plugins add
$.getJSON('app/site/hosting/scriptlet.nl...?action=availabledoc').
then(function(data){
var asHtml = format(data); //however you like
$("#relatedDocs").html(asHtml);
});
You can also go the whole module route. If you created a third party module DocsView then you would add DocsView as a child view to ItemDetailsView.
That's a little more involved so try the option above first to see if it fits your needs. The nice thing is you can just about ignore Backbone with this approach. You can make this a little more portable by using a service.ss instead of the suitelet. You can create your own ssp app for the function so you don't have to deal with SCAs url structure.
It's been a while, but you should be able to access the JSON data from within the related Backbone View class. From there, within the return context, output the value you're wanting to the PDP. Hopefully you're extending the original class and not overwriting / altering the core code :P.
The model associated with the PDP should hold all the JSON data you're looking for. Model.get('...') sort of syntax.
I'd recommend against Suitelets for this, as that's extra execution time, and is a bit slower.
I'm sure you know, but you need to set the documents to be available as public as well.
Hope this helps, thanks.

displaying the custom block only in full view mode in drupal7

Iam New to drupal.I have created a custom block in drupal7.Now In this Block I want to display the data of custom content type(i.e for example Advertisements).This Advertisements have a faciltity to display the ads in homepage,teaser,full view mode page.
Now the problem is I want to get programatically the view mode of block similar to node view so that I can get the advertisements related to that view(i.e advertisements with teaser view) etc..
This is how I have implemented but it failed to show the view mode
/**
* Implements hook_block_view().
*/
function Advertisement_block_view($delta = '',$view_mode) {
echo $view_mode;
$block['subject'] = t('Advertisements');
$block['content'] = Advertisement_block_content();
return $block;
}
Please help with this..
Thankyou
By default Blocks do not support view modes. Not the way nodes do at least as far as I know of. Take a look at the Drupal API on the hook_block_view() you used. It doesn't mention a $view_mode argument. You should actually be getting a warning if used.
Getting Advertisements (nodes) of a certain view mode sounds somewhat weird imo since you don't assign view modes onto nodes but onto a content type which means that all Advertisement nodes would be able to be viewed in a certain view mode once it is assigned to its content type.
If you want to get all view modes configured on a content type you can use: field_view_mode_settings($entity_type, $bundle) in which you pass $entity_type = 'node' & $bundle = 'Your_advertisement_content_type_machine_name'

scrape from web page into html

I will ask you a rather simple question (probably).
I would like to scrape a web page, namely:
http://www.carmudi.com.bd/mitsubishi-lancer-ex-12877-43.html?s_category=29&s_q=se129ca11xgiintcarmx&s_dir=desc&s_no_result_page=1&disable_previous=true
i would like to extract the informations shown into the box on the right
(containing price, accident ... and all those subparamenters)
and push them into a simple Html template.
Into the html, I would like to show a table containing the image and then a bullet point with, for example,
price
condition
What is the easiest way to do that?
Thank you so much for the help.
cheers,
Vincenzo
You may implement this using two methods:
Converting the required data to XML and then parse the data
Use Yahoo Query Language or YQL to parse the html to xml, ex:
http://query.yahooapis.com/v1/public/yql?q=select * from html where url="http://stackoverflow.com" and xpath='//div/h3/a'
The Xpath you need would be :
//*[#id="detail"]/div[1]/article/section[1]/div[2]/div[2]/table/tbody
Use DOM structure to access each data via javscript
var myDataTable = document.getElementById('detail').div[1].article.section[1].div[2].div[2].table;
Later use Element.innerHTML property to access data.

Populate other properties with a property

I have very recently been assigned to an EPiServer project. I'm .Net developer however, I had never had a pleasure of actually working with ES.
I have been given a task of creating a soft "integration" with SoundCloud. Our users would like to copy/paste URL to a SoundCloud song - which then I can use their API to actually get all information of the audio. (title, description, tags etc).
So what I have created so far
SoundcloudPageType (contains simple properties like title, description, duration etc.)
I have written little POC for Soundcloud API that gets me all information and deserializes it into object.
What I need now is a bridge between those two. I thought that creating something like "PageLinkReference" where you can click [...] button which would then ask you for "URL to SoundCloud audio", once person enters that I would do a REST api call to pre-populate all other properties on the page.
Now, this is just an idea. I would like to run it past you guys to see if
It is possible.
What is the best way of doing this and are there any tutorials that do something similar.
I do not want to hack and slash my way through EPiServer but to utilise what EPiServer might already provide.
I would add a short string property to the SoundcloudPageType and let the users paste into that field.
If you are using PageTypeBuilder something like this:
[PageTypeProperty(
EditCaption = "Soundcloud Url",
Type = typeof(PropertyString),
SortOrder = 2010,
UniqueValuePerLanguage = false,
Searchable = true)]
public virtual string SoundcloudUrl { get; set; }
Then you could either fetch "on request" or fetch and store (easiest on other properties you've added) in one of EPi's save events. Take a look at Joel's article of common patterns when integrating with EPi:
http://joelabrahamsson.com/episerver-integration-patterns/
You could use the oEmbed dynamic content plugin, which should support soundcloud
http://nuget.episerver.com/en/?search=oembed&sort=MostDownloads&page=1&pageSize=10

Resources