Try our conversational search powered by Generative AI!

Pre-populate ContentArea

Vote:
 

Hello.

 

I have been working on a block which will add sharing functionality to pages. This works all fine but the problem is that I want to pre-populate this block into certain pagetypes (e.g. Newspages). I thought I could do this by adding the block in the SetDefaultValues-method however that requires me to have the actual IContent. I can think of three approaches, however I have not had any success with any of them.

  1. Load a specific instance of the block perhaps specified by Name.
  2. Load any instance of the block (I could not find any Get<T>(ContentType type)).
  3. Load the default values of the block. (What happens when I try to move the block or edit the ContentArea?)

Perhaps we can solve this out. Thanks in advance!

David Rutqvist

#72720
Jun 27, 2013 9:16
Vote:
 

When you say "requires me to have the actual IContent", do you mean the IContent of the Block that needs the default values (for example CurrentBlock) or the IContent of the blocks you want to have as default values?

#72721
Jun 27, 2013 9:24
Vote:
 

Not sure if I understand you right but I will try to explain.

The reason I need IContent is to be able to add the Block to the ContentArea (using ContentArea.Add(IContent content)). The Block itself does not use any EPi-Block related properties (e.g. CurrentBlock) but maybe that is needed to be able to edit the contentarea.

In clear words: what I am trying to achieve is that when I create a new page of pagetype NewsPage should there already be a "SharingBlock" in the NewsPage's ContentArea called SubArea.

#72723
Jun 27, 2013 9:30
Vote:
 

Ah I see, I think I missunderstood your intent.

I would suggest that you create a ContentArea in a page such as your StartPage or preferebly if you have a some kind of Settings Page.

When you create your NewsPage, you Get your StartPage/SettingsPage and copy the ContentArea value to your new NewsPage

#72724
Edited, Jun 27, 2013 9:33
Vote:
 

Yeah that works for now. If anyone got a solution which does not include creation of another property would I be glad to hear it.

#72727
Jun 27, 2013 10:50
Vote:
 

I would suggest that you in one way or another have a Property or Setting where you define your default values.

If you want to refer to an existing Block you do not want to hard code Id values or similar that refers to your "SharingBlock" into your code.

Or is the case that you want to create a new instance of your SharingBlock each time you create a NewsPage?

#72728
Jun 27, 2013 10:53
Vote:
 

Yeah I have thought about that too and I came across the same thought to prevent hardcoding. Creating a new instance could be a solution but that would create a lot of waste blocks. Then I could rather have all the block stuffs inside the pagetype itself. A GetAny-solution could have worked though since there probably only will be one instance of the block.

#72732
Jun 27, 2013 10:58
Vote:
 

I think it depends on if you want to put in more blocks except that SharingBlock, then ContentArea would be ideal. Otherwise only having a ContentReference or maybe a Local Block (a public virtual SharingBlock {get;set;} on your Page Type) and populate the Local Block Properties when you create your Page?

Which leads me to the question. What kind of information do you have on your SharingBlock?

I agree about creating a new instance would create alot of waste blocks so I would not walk along that road.

What do you mean with a "GetAny-solution", find any instance of SharingBlock among all your created Blocks?

#72734
Jun 27, 2013 11:13
Vote:
 

The block's properties ar for instance ShowFacebook (bool), showTwitter etc. nothing else than bool. And yes that was what I meant when saying GetAny().

#72767
Jun 28, 2013 7:49
Vote:
 

Ok I think I understand

I think that if the case is following:
* You're not going to add more Content such as Pages or Blocks in that ContentArea AND
* You're interested in always setting showing/hiding Facebook or Twitter on each page instead of controlling multiple Pages with only one place to show/hide Facebook or Twitter (as a Shared Block)

I would suggest that you add a SharingBlock as a Local Block to your Page Type, and you should be able to set your default values on SetDefaultValues on your NewsPage or your SharingBlock.

#72772
Jun 28, 2013 11:01
This thread is locked and should be used for reference only. Please use the Episerver CMS 7 and earlier versions forum to open new discussions.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.