Take the 2-minute tour ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

in my page.tpl.php i'm doing this to display one of my view:

print views_embed_view('teaserview', 'default');

that gives me the following html output:

<span thmr="thmr_10">
<div class="view view-teaserview view-id-teaserview view-display-id-default view-dom-id-e051ba535ce9aac6cd9a0d564b3dbb29 contextual-links-region">
    <div class="contextual-links-wrapper">
        <span thmr="thmr_16">
        <ul class="contextual-links">
            <li class="views-ui-edit first last"><span thmr="thmr_17"><a href="/kbi/admin/structure/views/view/teaserview/edit/default?destination=node/3">Edit view</a></span></li>
        </ul>
        </span>
    </div>
    <div class="view-content">
        <span thmr="thmr_15">
        <div class="views-row views-row-1 views-row-odd views-row-first views-row-last">
            <span thmr="thmr_14">
            <span thmr="thmr_11"><span thmr="thmr_12"><span thmr="thmr_13"><img src="http://127.0.0.1/kbi/sites/default/files/teaser_2.jpg" width="1029" height="308" alt="" /></span></span></span></span>
        </div>
        </span>
    </div>
</div>
</span>

but the only thing that i really need is

<img src="http://127.0.0.1/kbi/sites/default/files/teaser_2.jpg" width="1029" height="308" alt="" />

is there a possibility to modify the views_embed_view call so that i get only the needed data?

there would be the possibility to modify all the views .tpl.php files but i hope there's an easier way to do this.

i also read about the semantic views module but i didn't understand how to configure my view with it so that i get only the needed markup as output. it didn't seem to have any effect.

share|improve this question
    
Which version of Drupal/Views are you using? Views 3 has settings per view for this, I'm sure they'll pass over into a programatically embedded view. –  Chapabu Mar 15 '12 at 8:55
    
i'm using views 3... which settings are you refering to? –  toxinlabs Mar 15 '12 at 12:22
add comment

3 Answers 3

If you go into the view thru the Views UI, and look at the fields, you can configure/remove the wrapper html from the field by selecting none for the wrapper of the field, and that should take a lot, if not all, of the html away that you don't want. Also, if you go into the views admin screen and go to tools, you can check the "Do not show hover links over views" which should remove the first edit portion of all of your views when looked at via an admin type account as well.

If the above doesn't take away all the html you want, you can either modify the templates as you mentioned above, or use something like this instead of views_embed_view:

$view = views_get_view('teaserview');
$display_id = 'default';
$view->set_display($display_id);
$view->execute();

which will execute but not display the view ... but will create a $view->result which is an array of row objects basically, so you could then go in there and print out whatever you wanted.

To find out what is in there, throw in a

drupal_set_message('<pre>' . print_r($view->result, true) . '</pre>');

and you'll see what you can work with.

PS Once you have this working, I would put it in a preprocess hook and assign this output to a variable instead of putting any/all of this code in your page.tpl, too...

PPS I also am assuming you know that the Theme Developer module is throwing a lot of html in there as well (all those thmr='s as such).

share|improve this answer
    
you're right, some stuff i couldn't get rid of was from theme developer ... damn ;) –  toxinlabs Mar 15 '12 at 17:40
    
she can be a cruel mistress –  Jimajamma Mar 15 '12 at 18:02
    
true :). just getting started with drupal a LOT to learn. –  toxinlabs Mar 16 '12 at 1:15
add comment
up vote 1 down vote accepted

i think i have it running ok now, you tell me if this is the most elegant way ;)

i copied the views-view--[ViewName].tpl.php to my theme folder and made the following changes:

<div class="<?php print $classes; ?>">     // delete this line
  <?php print render($title_prefix); ?>
  <?php if ($title): ?>
[...]
<?php if ($header): ?>
    <div class="view-header">   // delete this line
      <?php print $header; ?>
    </div>                      // delete this line
  <?php endif; ?>
[...]
<?php if ($rows): ?>
    <div class="view-content">  // delete this line
      <?php print $rows; ?>
    </div>                      // delete this line
  <?php elseif ($empty): ?>

and then i made some adjustments in the view editor (i installed the semantic views module):

Format: Semantic Views

Show: Semantiv Views: Fields

then in the field settings:

multiple field settings

[x] display all values in the same row

[x] simple seperator (and then just empty the seperator text field so that no seperator is inserted in the output)

rewrite results:

[x] strip HTML tags

[x] remove whitespace

Preserve certain tags: (in my case i'm displaying image fields, so depending on the content of your fields this may differ)

-> this gives me a clean

<img src="http://127.0.0.1/kbi/sites/default/files/teaser_2.jpg" width="1029" height="308" alt="" />

at the end.

share|improve this answer
    
all is well and good if it is easy to understand on your own site, but I would instead of editing views-view.tpl.php, which [ae]ffects all views, I'd edit views-view--VIEWNAME.tpl.php or views-view--VIEWNAME-DISPLAYNAME.tpl.php instead. –  Jimajamma Mar 15 '12 at 19:30
    
you're right, thanks! –  toxinlabs Mar 15 '12 at 20:16
add comment

You should try Fences, an alternative to Semantic Views

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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