I'm trying to get a variable from a view to display on a block. For example "We have 200 blog posts" (200 being the variable). Right now I'm using the views_embed_view method. The problem is the view includes a bunch of mark up I don't need/want (the container, theme, etc)

Is it possible to just call the field I want? I know I could create a whole custom theme for the view without markup but I'm hoping there is an easier way.

2 Answers 2


You can use Views UI to strip out the extra layers of styling for list/rows/fields if you're using an unordered list view. For list/rows, there's the settings link that allows you to toggle off row elements and field wrappers.

enter image description here enter image description here

For fields, there's the Style Settings fieldset that lets you customize your field wrapper markup.

enter image description here

  • Thanks. This combined with a template completed got rid of all markup.
    – Sam
    Apr 25, 2015 at 17:31

If what you're trying to get is the number of results returned from the view then your best bet might be to call views_get_view_result():

$result = views_get_view_result($name, $display_id);
$num_blogposts = count($result);

However, if that's what you're trying to achieve then it might be better from a performance point of view to bypass views entirely and get the count with an EntityFieldQuery.

-- EDIT --

Option 2:

You could override the various templates that make up the view, removing any unnecessary markup from each.

To do this, Click on "Theme: Information" in the "Advanced" section of the view edit page (bottom right) and you'll see a list of templates used. Click each one in turn and create a new file in your theme folder and copy in the contents before removing any unnecessary markup.

What you name the file is important, back on the list of templates, note that each one has a large number of filename suggestions, ranging from very generic to very specific. Choose the name with the the most appropriate degree of specificity and name your file that. note that for example calling your Display Output template file "views-view.tpl.php" will mean that your override will have effect on every single view across your site, so a more specific filename should lock it down to a specific view/display/etc.

Once you've done this, you'll need to flush the theme registry cache before you'll see the change. The easiest way to do that is by clicking "Rescan template files" at the bottom of the theme information dialogue.

Finally note that these updates won't change what you see in the views preview unless you also make these changes for the admin theme.

note that if you are also rendering the view normally (in addition to the views_embed_view) where you want to see the original markup then you should probably use a new display of the view for this and make sure your template names only target the correct display.

  • I already have the view set up to give me the value I want it has a field that displays the "200". I'm just trying to print that field without the the additional markup.
    – Sam
    Apr 25, 2015 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.