Use Matrix field to output specific html I am quite new to this so, please be patient. I am wanting to output the following html:

&lt;script type="text/javascript" src="js/jquery.jcarousel.min.js"&gt;&lt;/script&gt;
&lt;script type="text/javascript" src="js/jcarousel.responsive.js"&gt;&lt;/script&gt;
&lt;div class="jcarousel-wrapper"&gt;
    &lt;div class="jcarousel"&gt;
        &lt;ul&gt;
            &lt;li&gt;
                &lt;img src="images/home-slider-1.jpg" alt="home slider image"&gt;
                &lt;div class="white-logo"&gt;&lt;/div&gt;
                &lt;div class="jcarousel-text"&gt;
                    &lt;p&gt;Helping you to establish your outdoor brand in the world of retail and e-commerce&lt;/p&gt;
                &lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
                &lt;img src="images/home-slider-2.jpg" alt="home slider image"&gt;
                &lt;div class="white-logo"&gt;&lt;/div&gt;
                &lt;div class="jcarousel-text"&gt;
                    &lt;p&gt;One of our top brands&lt;/p&gt;
                &lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
                &lt;img src="images/home-slider-3.jpg" alt="home slider image"&gt;
                &lt;div class="white-logo"&gt;&lt;/div&gt;
                &lt;div class="jcarousel-text"&gt;
                    &lt;p&gt;We also have a design service&lt;/p&gt;
                &lt;/div&gt;
            &lt;/li&gt;
            &lt;li&gt;
                &lt;img src="images/home-slider-4.jpg" alt="home slider image"&gt;
                &lt;div class="white-logo"&gt;&lt;/div&gt;
                &lt;div class="jcarousel-text"&gt;
                    &lt;p&gt;Visit us at our new site&lt;/p&gt;
                &lt;/div&gt;
            &lt;/li&gt;
        &lt;/ul&gt;
    &lt;/div&gt;
    &lt;a href="#" class="jcarousel-control-prev"&gt;&lt;img src="images/nivo-nav-buttons.png"&gt;&lt;/a&gt;
    &lt;a href="#" class="jcarousel-control-next"&gt;&lt;img src="images/nivo-nav-buttons.png"&gt;&lt;/a&gt;
&lt;/div&gt;


I have a Matrix field set up as follows:

Field handle: homepageSlider
Block type handle: homeSlider
Field name handles: mainImage, whiteLogo, imageText and mainImage.

mainImage has a field type of 'Assets'
whiteLogo has a field type of 'Lightswitch'
imageText has a field type of 'Plain Text'
mainImageLink has a field type of 'Linkit' (from a plugin).

So far, I have written:

{% block content %}

{% includeJsFile "/js/jquery.jcarousel.min.js" %}
{% includeJsFile "/js/jcarousel.responsive.js" %}
&lt;div class="jcarousel-wrapper"&gt;
&lt;div class="jcarousel"&gt;
&lt;ul&gt;

{% for block in entry.homepageSlider %}
&lt;li&gt;

{% if block.type == "mainImage" %}
{% set image = block.mainImage %}
&lt;img src="{{ image.getUrl }}" alt="{{ image.title }}"&gt;
{% endif %}

{% if block.type == "whiteLogo" %}
&lt;div class="white-logo"&gt;
{% set imagetwo = block.mainImage %}
&lt;img src="{{ imagetwo.getUrl }}" alt="{{ imagetwo.title }}"&gt;
&lt;/div&gt;
{% endif %}

{% if block.type == "imageText" %}
&lt;div class="jcarousel-text"&gt;&lt;p&gt;{{ block.imageText }}&lt;/p&gt;&lt;/div&gt;
{% endif %}

{% if block.type == "mainImageLink" %}
{% set yourLink = entry.mainImageLink %}
{{ yourLink.link|raw }}
{% endif %}

&lt;/li&gt;

{% endfor %}
&lt;/ul&gt;
&lt;/div&gt;
&lt;a href="#" class="jcarousel-control-prev"&gt;&lt;img src="images/nivo-nav-buttons.png"&gt;&lt;/a&gt;
&lt;a href="#" class="jcarousel-control-next"&gt;&lt;img src="images/nivo-nav-buttons.png"&gt;&lt;/a&gt;
&lt;/div&gt;


This outputs html as I want, BUT, is empty between &lt;li&gt; and &lt;/li&gt;. I have tried following this post, but am so far getting nowhere.

Any help that anyone can offer would be most appreciated.

With kind regards,

Mark
In your code block.type is the matrix block type, ie homeSlider. 

There's alot going on in your code that I'm not sure is intended or not, but let's say you had the fields mainImage and imageText as required fields in there, and have an optional whiteLogo (not sure where that link's suppose to go, it's not in your original html). Try something like this:

{% includeJsFile "/js/jquery.jcarousel.min.js" %}
{% includeJsFile "/js/jcarousel.responsive.js" %}
&lt;div class="jcarousel-wrapper"&gt;
&lt;div class="jcarousel"&gt;
&lt;ul&gt;
  {% for block in entry.homepageSlider %}
  &lt;li&gt;
    {% set image = block.mainImage.first() %}
    &lt;img src="{{ image.getUrl }}" alt="{{ image.title }}"&gt;

    {% if block.whiteLogo %}
      &lt;div class="white-logo"&gt;&lt;/div&gt;
    {% endif %}

    &lt;div class="jcarousel-text"&gt;&lt;p&gt;{{ block.imageText }}&lt;/p&gt;&lt;/div&gt;
  &lt;/li&gt;
  {% endfor %}
&lt;/ul&gt;
&lt;/div&gt;


So, inside you're for loop, the fields you've created are accessible by block.fieldHandle. If you want to make a conditional based on if a field has a value or not, that is done in different ways depending on the type of field. So you'd do {% if block.lightswitchField %} if it's a lightswitch, {% if block.assetField | length %} if it's an assets field, or {% if block.textField != '' %} if it's a text field.

Hope that helps you in the right direction.