Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8762769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:37:02+00:00 2026-06-13T15:37:02+00:00

I’m trying to create some custom code inside my Sub Layout. I have to

  • 0

I’m trying to create some custom code inside my Sub Layout.

I have to build a newsletter, the newsletter can be composed on a number of article.
An article can be composed by a title / Sub title / Header and image.

Can be, because the Sub title or the image are not mandatory.
To avoid any empty space / missing image in the newsletter email, I would like to create a specific HTML based on the content.

If there is no image, don’t show the Image control, if there is no Sub title, don’t show the Sub Title control;

To do that, I’m using the following code which is not working 🙁

    Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
Sitecore.Data.Items.Item home = master.GetItem("/sitecore/content/Home");

if(home != null && home.Fields != null)
{
string name = home.Fields["Image"].Name; -> Which Fields["Image"] returns null.
}

Is there another way to retreive the field of the selected article ? As my code is not working at all, I don’t understand how to retreive the Field value of my selected Item.

Thank you.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T15:37:03+00:00Added an answer on June 13, 2026 at 3:37 pm

    In your example, home.Fields is just checking to make sure that the Fields collection exists. You aren’t checking if there is a value in the Image field before trying to extract the name.

    You probably need something like this:

    if(home != null && home.Fields != null && home.Fields["Image"] != null)
    {
       string name = home.Fields["Image"].Name;
    }
    

    Per your comments, it seems to be you are actually trying to pull the image field from the datasource of your component. If you want to conditionally check for the image field before doing something in that case, there are a lot of possible null exceptions that I would want to handle. The code should probably be something like:

    var parent = ((Sitecore.Web.UI.WebControl)Parent);
    if(parent != null){
       Item dataSourceItem = string.IsNullOrWhiteSpace(parent.DataSource) ? null : Sitecore.Context.Database.GetItem(parent.DataSource);
    
       if(dataSourceItem != null && dataSourceItem.Fields != null && dataSourceItem.Fields["Image"]!=null){
           string name=dataSourceItem.Fields["Image"].Name;
       }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have just tried to save a simple *.rtf file with some websites and
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have this code to decode numeric html entities to the UTF8 equivalent character.
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I'm trying to create an if statement in PHP that prevents a single post
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
I'm new to using the Perl treebuilder module for HTML parsing and can't figure

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.