I'm cycling through a list using {% for item in list %}  and I want to output something like this:  &lt;li&gt;One&lt;/li&gt; &lt;li class='alternate'&gt;Two&lt;/li&gt; &lt;li&gt;Three&lt;/li&gt; &lt;li class='alternate'&gt;Four&lt;/li&gt; ...   with the intention of styling the alternate lines a different colour.  Django (1.3) has no mod or div template tag operators. I know I can add them by manipulating the django source, but I'd rather not do that as I want to be able to package this app up.  How can I achieve this?
120851
Django templates offer the builtin tag cycle for alternating between several values at different points in a template (or for loop in a template) but this tag does not reset when it is accessed in a scope outside of the cycles definition.  I.e., if you have two or more lists in your template, the rows of all of which you'd like to use some css definitions odd and even, the first row of a list will pick up where the last left off, not with a fresh iteration from the choices (odd and even)  E.g., in the following code, if the first blog has an odd number of entries, then the first entry in a second blog will start as even, when I want it to start at odd.  {% for blog in blogs %}   {% for entry in blog.entries %}     &lt;div class="{% cycle 'odd' 'even' %}" id="{{entry.id}}"&gt;       {{entry.text}}     &lt;/div&gt;   {% endfor %} {% endfor %}   I've tried obviating this by patching with the resetcycle tag offered here:    to no avail.  (The code didn't work for me.)  I've also tried moving my inner loop into a custom tag, but this also did not work, perhaps because the compile/render cycle moves the loop back into the outer loop?  (Regardless of why, it didn't work for me.)  How can I accomplish this simple task!?  I'd prefer not to create a data structure in my view with this information pre-compiled; that seems unnecessary.  Thanks in advance.
108700
I'm trying to wrap multiple field items in an HTML container.  So let's say I have "Blog" content type. I have field1, field2, field3, field4 and field5 for this content type.   I want to output field2, field3 and field4 wrapped together in a DIV.  I've been Googling and tinkering for the past 3 hours and I haven't gotten anywhere.  Any help out there?  Drupal 7, Zen subtheme.   I read this and didn't have any luck here either:
50386
I have a code, that outputs a standard pager:  print theme('pager');   it outputs this:  &lt;h2 class="element-invisible"&gt;Pages&lt;/h2&gt; &lt;div class="item-list"&gt; &lt;ul class="pager"&gt;&lt;li class="pager-current first"&gt;1&lt;/li&gt; &lt;li class="pager-item"&gt;&lt;a title="Go to page 2" href="/drupal/node?page=1"&gt;2&lt;/a&gt;&lt;/li&gt; &lt;li class="pager-item"&gt;&lt;a title="Go to page 3" href="/drupal/node?page=2"&gt;3&lt;/a&gt;&lt;/li&gt; &lt;li class="pager-next"&gt;&lt;a title="Go to next page" href="/drupal/node?page=1"&gt;next ›&lt;/a&gt;&lt;/li&gt; &lt;li class="pager-last last"&gt;&lt;a title="Go to last page" href="/drupal/node?page=5"&gt;last »&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;   How can I change the HTML to something like this:  &lt;ul class="pagination"&gt;     &lt;li&gt;&lt;a href="#"&gt;&amp;lt;&lt;/a&gt;&lt;/li&gt;     &lt;li&gt;&lt;a href="#"&gt;1&lt;/a&gt;&lt;/li&gt;     &lt;li&gt;&lt;a href="#" class="active"&gt;2&lt;/a&gt;&lt;/li&gt;     &lt;li&gt;&lt;a href="#"&gt;3&lt;/a&gt;&lt;/li&gt;     &lt;li&gt;&lt;a href="#"&gt;&amp;gt;&lt;/a&gt;&lt;/li&gt; &lt;/ul&gt;   I looked into this thread: , created a function bartik_preprocess_custom_pager and a file custom-pager.tpl.php inside my Bartic theme templates, but I can't make it work.  print theme('custom_pager');   outputs nothing. Does anybody know, how can I customize the HTML output for a pager, creating one just for 1 page?
28523
Here's a PHP example of mine. Can anyone find a shorter/easier way to do this?  &lt;? foreach($posts as $post){?&gt;     &lt;div class="&lt;?=($c++%2==1)?‘odd’:NULL?&gt;"&gt;         &lt;?=$post?&gt;     &lt;/div&gt; &lt;? }?&gt;  &lt;style&gt;     .odd{background-color:red;} &lt;/style&gt;   Examples in other languages would be fun to see as well.
38806
The input in file field.html.twig is normally like this:  {% for item in items %} &lt;div{{ attributes }}&gt;{{ item.content }}&lt;/div&gt; {% endfor %}   And you get the output in HTML like this:  &lt;div&gt;&lt;img src="path/to/image/image.png" alt="my wonderful image"&gt;&lt;/div&gt;   But I want to add a class to img-tag. How do I receive the following output:  &lt;div&gt;&lt;img class="img-fluid" src="path/to/image/image.png" alt="my wonderful image"&gt;&lt;/div&gt;   I am looking for a solution like , but it is not working. Can anybody help?
120233
I would like to be able to pass aarguments to operators that I am calling from panels/buttons but I do not know how to do that. At the moment I use "global" variables but they tend to make the code a bit like a puzzle since I need to constantly update them.  See the code below, in that example I would like to pass an argument (like ARG) to "object.simple_operator" when the button is clicked.  import bpy     def DO_SOMETHING(arg):      print(arg)  return  class SimpleOperator(bpy.types.Operator):     """Tooltip"""     bl_idname = "object.simple_operator"     bl_label = "Simple Object Operator"      @classmethod     def poll(cls, context):         return context.active_object is not None      def execute(self, context):         DO_SOMETHING(ARG)         return {'FINISHED'}    class MyPanel(bpy.types.Panel):      bl_label = "mypanel"     bl_idname = "OBJECT_PT_MyPanel"      def draw(self, context):          layout = self.layout          wm = context.window_manager          obj = context.object          row = layout.row()         row.operator('object.simple_operator')
84084
I'm trying to get a list of custom labels. Here is what I've tried:  \begin{enumerate}[Exercise (1)]  \item first  \item second  \end{enumerate}   This results in each item being labeled as: Exerc#se (#)  Where # is the number of the item in the list. How can I make the "i" in exercise not be pattern matched?   Using a \ doesn't work, it causes syntax error.
80271
I'd like to colorize the names of header files included in angle brackets (&lt;>) in my C examples formatted by the listings package. In the MWE I'd like &lt;brackets.h&gt; to be orange too like "quotes.h". I don't want to do that manually with escapes in every listing but globally. I have tried various crude things including the use of keywordcommentsemicolon (which did not work at all because it is an undefined key although it is mentioned in the documentation... does it need to be enabled?). The most promising results were achieved by using morecomment=[s]{&lt;}{&gt;}. However, that would colorize everything following a &lt;... which is not that uncommon in C ;) The solution should work independently from the documentclass, especially beamer should work, and preferably work with common listings options (i.e., not change the behavior of other formatting options such as identifierstyle.  \documentclass{article} \usepackage[utf8]{inputenc} \usepackage[T1]{fontenc}  \usepackage{xcolor} \definecolor{darkorange}{HTML}{C87B0F}  \usepackage{listings} \lstset{language=C,captionpos=b} \lstloadlanguages{C}  \lstset{%     stringstyle=\color{darkorange},     identifierstyle={\color{blue}}. }  \begin{document}  \begin{lstlisting}[gobble=4]     #include &lt;stdlib.h&gt;     #include "quotes.h"      int main(int argc, char **argv) {          if (argc &lt;= 3)             return 0 &gt; **argv;         return EXIT_SUCCESS;     } \end{lstlisting}  \end{document}
36880
Oftentimes, I want to include code samples in a list, for example:   Item One Item Two, for example: private bool ItemTwo() {     return this.IFeelLucky; } Item Three   The problem is that there isn't a good and intuitive way to do this using . It's doable, but you have to do some formatting black-magic to get it that way, which is just not "nice" to deal with.  Source that produces this:  1. Item One 2. Item Two, for example: &lt;br/>&lt;br/>&lt;pre>&lt;code>private bool ItemTwo()     {         return this.IFeelLucky;     }&lt;/code>&lt;/pre> 3. Item Three    I would love to just be able to do it this way:  1. Item One 2. Item Two, for example:      private bool Test()     {         return this.IFeelLucky;     }  3. Item Three  Which results in, well, this:   Item One Item Two, for example:  private bool Test() {     return this.IFeelLucky; } Item Three
31923
I'm using the following list:  &lt;ol id="footnotes"&gt;     &lt;a name="footnote1"&gt;&lt;li&gt;&lt;/a&gt;This is the first footnote...&lt;/li&gt;     &lt;a name="footnote2"&gt;&lt;li&gt;&lt;/a&gt;This is the second footnote...&lt;/li&gt; &lt;/ol&gt;   With the following .css:  #footnotes {list-style-type: decimal;             list-style-color: #f90;             }  #footnotes li            {color: #000;             }  #footnotes a li, #footnotes li a            {color: #f90;             }   The aim is to have the li/footer text itself black (#000), and the number styled to orange (#f90).  I've tried using the list-style-color property but this does nothing except upset the Web developer toolbar (in FF3.0.8/Ubuntu 8.04), Midori similarly doesn't display the number in orange (I thought I'd try it in the Webkit engine, just in case...).  Any ideas?  Edited the HTML (since I remembered that the  tag doesn't necessarily need to enclose anything to function as an anchor):  &lt;ol id="footnotes"&gt;     &lt;li&gt;&lt;a name="footnote1"&gt;&lt;/a&gt;This is the first footnote...&lt;/li&gt;     &lt;li&gt;&lt;a name="footnote2"&gt;&lt;/a&gt;This is the second footnote...&lt;/li&gt; &lt;/ol&gt;   In response to those that suggest using a &lt;span&gt; inside the &lt;li&gt;...yeah. That occurred, though I thank you for the suggestions and the time taken, but I was looking (li'l standardista that I am... ;) ) for a more...semantic option.  As it is, I think I'll probably use that approach. Though I accepted a different, Pete Michaud's, answer due to its sheer informative nature. Thanks!
25980
suggested to have templates for tags. Their example was with the  tag on Stack Overflow.  I'm suggesting a more general approach:  Templates, Mark II  I suggest that each site will have a template. That template will prefill the  textbox when a new question is asked. However, it will be completely optional.  Something like (for Stack Overflow):  ## The Problem ## { Please tell us what the problem is with as many details as possible.   Include language, operating system, and any other relevant information.   Remember to add the relevant tags below, too. } ## Attempted Solutions ## { Please tell us what you've tried so far. Have you tried searching Google?    What queries? } ## Existing Code ## { Do you have any existing code to show? Please keep it short and simple.    We should be able to detect the problem right away. }   Why am I suggesting this?  Well, it seems as though most users will stick with the default. They don't bother to read, and so prefilling the question form for them with information that we know might be relevant, will forceWe'll get to that in a second them to actually stop and read.  Scenarios:   Best case: User arrives to ask a question, actually reads the template, fills the correct information in the placeholders. (Yeah, because that'll happen a lot) Neutral: User simply removes all of the template text and rewrites their own question. Result is exact same as we have currently. Worst case: User will ignore or misunderstand the template, will use it wrong or not at all and we'll get something like  &lt;template text here, still unfilled&gt; &lt;(crappy) question&gt;   This can be solved in a couple different ways. We could detect the template tags (i.e. { }, subject to discussion), and throw an error when a user attempts to post with them still available. We could also act more autonomously and remove placeholders which still exist.    Some more points:   Templates should be per-site, not per-tag. Sure, there are differences between the tags, but all questions are expected to have the same general information, and this isn't meant to be a rule, but a guideline to help write better questions. Site templates should be editable by that site's mods, like close reasons. We could autofocus on the first placeholder, and perhaps implement TAB to jump from one placeholder to the other, similar to mixins in IDEs. This doesn't have to be implemented everywhere. This suggestion makes sense to Stack Overflow or Superuser, but not to Anime &amp; Manga or Gaming All of the details are subject to discussion, and all discussion is welcomed.
95253
I made a panel with an Export Modified Model STL button. Right now I am using... class Export_STL(bpy.types.Operator):     bl_idname = &quot;diamond.export_stl&quot;     bl_label = &quot;Export Modified Model STL&quot;      def execute(self, context):         bpy.ops.export_mesh.stl('INVOKE_DEFAULT')         self.report({'INFO'}, f&quot;This is {self.bl_idname}&quot;)         return {'FINISHED'}  It works but I need the default settings to have &quot;Batch Mode&quot; to Object&quot; and a check on the &quot;Selection Only&quot;. How do I write this in the script?
72471
In , I've found one solution to produce a zebra effect for listing. Unfortunately, this only works if the lines are not broken. Is there a way to fix this?  Here is a code with an example showing the problem:  \documentclass[10pt,a4paper]{article}     \usepackage[utf8x]{inputenc}     \usepackage{ucs}     \usepackage[T1]{fontenc}     \usepackage{lmodern}     \usepackage[frenchb]{babel}     \usepackage[x11names, svgnames]{xcolor}     \usepackage{graphicx}     \usepackage{listings}     \usepackage{amsfonts}     \usepackage{amssymb}      \makeatletter         % Patch line number key to call line background macro         \lst@Key{numbers}{none}{%             \def\lst@PlaceNumber{\lst@linebgrd}%             \lstKV@SwitchCases{#1}%             {none&amp;\\%              left&amp;\def\lst@PlaceNumber{\llap{\normalfont                         \lst@numberstyle{\thelstnumber}\kern\lst@numbersep}\lst@linebgrd}\\%              right&amp;\def\lst@PlaceNumber{\rlap{\normalfont                         \kern\linewidth \kern\lst@numbersep                         \lst@numberstyle{\thelstnumber}}\lst@linebgrd}%             }{\PackageError{Listings}{Numbers #1 unknown}\@ehc}}          % New keys         \lst@Key{linebackgroundcolor}{}{%             \def\lst@linebgrdcolor{#1}%         }         \lst@Key{linebackgroundsep}{0pt}{%             \def\lst@linebgrdsep{#1}%         }         \lst@Key{linebackgroundwidth}{\linewidth}{%             \def\lst@linebgrdwidth{#1}%         }         \lst@Key{linebackgroundheight}{\ht\strutbox}{%             \def\lst@linebgrdheight{#1}%         }         \lst@Key{linebackgrounddepth}{\dp\strutbox}{%             \def\lst@linebgrddepth{#1}%         }         \lst@Key{linebackgroundcmd}{\color@block}{%             \def\lst@linebgrdcmd{#1}%         }           % Line Background macro         \newcommand{\lst@linebgrd}{%             \ifx\lst@linebgrdcolor\empty\else             \rlap{%                 \lst@basicstyle                 \color{-.}% By default use the opposite (`-`) of the current color (`.`) as background                 \lst@linebgrdcolor{%                 \kern-\dimexpr\lst@linebgrdsep\relax%                 \lst@linebgrdcmd{\lst@linebgrdwidth}{\lst@linebgrdheight}{\lst@linebgrddepth}%                 }%             }%             \fi         }     \makeatother      \lstset{ %    * Number for lines         numbers=left,                   % Where to put the line-numbers         numberstyle=\footnotesize,      % Size of the fonts used for the line-numbers         stepnumber=1,                   % Step between two numbers         numbersep=5pt,                  % How far the line-numbers are from the code % %    * Back returns for long lines         breaklines=true,                % Sets automatic line breaking         breakatwhitespace=false,        % Automatic breaks only happen at whitespace ?         breakindent=0pt,                % Space before the text of a break         postbreak=\mbox{                % Character used at the begining of a break             \rotatebox[y=0.9ex]{180}{\color{Red} $\Lsh$}%         },     }  \begin{document}  \begin{lstlisting}[language=Python,linebackgroundcolor={\ifodd\value{lstnumber}\color{gray}\fi}] for i in range(5): for i in range(5): for i in range(5): for i in range(5): for i in range(5): for i in range(5):     sum += i**3 print sum  print('Fin de la boucle...') \end{lstlisting}  \end{document}
106588
The styling of nested lists with mixed or multiple child elements isn’t great. If you have only a single paragraph of text or a single nested list item within a parent list item then there’s no issue, but as soon as you have more than one child element the styling starts to get a bit unpredictable. This is most noticeable when you have nested lists along with paragraph text in the same parent list item, but also affects things like code blocks and quotes.  This has come up as a support issue (for example  and ).  The issue is the explicit lack of a bottom margin on child lists and paragraphs regardless of whether there are succeeding elements. So for example, this:  - List item      - Child list item      More list item text  - List item   Is rendered as:        List item         Child list item         More list item text   List item      And as an image for posterity:        This is because the first "List item" text is wrapped in a &lt;p&gt; tag that has a bottom margin, whereas the child list item and "Child item text" has no bottom margin.  The offending CSS rules (found in "all.css") are:  ul ul, ol ul, ul ol, ol ol {     margin-bottom: 0; }  .post-text ul p:last-of-type, .wmd-preview ul p:last-of-type, .post-text ol p:last-of-type, .wmd-preview ol p:last-of-type {     margin-bottom: 0; }   Now, we don’t want all nested lists to have no bottom margin and we don’t the last paragraph to have no bottom margin unless it is the last element in that list item, not just the last paragraph.  The simple solution is to remove both of those declarations and replace with:  ul :last-child, ol :last-child {     margin-bottom: 0; }   That gives us no bottom margin on the last child element of anything inside lists, which would also cover the last list item itself, meaning we could get rid of this (also in "all.css") too:  .post-text ul li:last-child, .wmd-preview ul li:last-child, .post-text ol li:last-child, .wmd-preview ol li:last-child {     margin-bottom: 0; }   Just for reference, this is how the previous example looks with the improved CSS:        Maybe I’m overlooking some other case where those rules are important or maybe they're used elsewhere and simply removing them isn't the best option but at least change the rule affecting paragraphs from :last-of-type to :last-child and stop removing the bottom margin on all nested lists...  This is also a problem with non-nested lists when multiple paragraphs are used. This:  - List item   Second paragraph for item  - List item  - List item   is rendered like this:        List item      Second paragraph for item   List item   List item      as an image for posterity:        The second paragraph of the first item shouldn't be visually closer to the second item than it is to the preceding paragraph in the first item.  TL;DR Better nested list spacing please.
121033
I'm trying to figure out how to alter the output of a Views Block. The first image shows the situation that I'm stuck in, which obviously looks horrible, and the bottom two images are of what I would like to see, as well as the likely div plan. This is my first time working on this type of issue, so if someone has an idea of where to go, or if there is a module available for me to work with. I'm just looking for the cleanest way of getting to the output goal. Thanks!
80790
If I have a list like this:  &lt;ul id="mylist"&gt;     &lt;li id="list-item1"&gt;text 1&lt;/li&gt;     &lt;li id="list-item2"&gt;text 2&lt;/li&gt;     &lt;li id="list-item3"&gt;text 3&lt;/li&gt;     &lt;li id="list-item4"&gt;text 4&lt;/li&gt; &lt;/ul&gt;   What's the easiest way to re-arrange the DOM nodes to my preference? (This needs to happen automatically when the page loads, the list-order preference is gained from a cookie)  E.g.  &lt;ul id="mylist"&gt;     &lt;li id="list-item3"&gt;text 3&lt;/li&gt;     &lt;li id="list-item4"&gt;text 4&lt;/li&gt;     &lt;li id="list-item2"&gt;text 2&lt;/li&gt;     &lt;li id="list-item1"&gt;text 1&lt;/li&gt; &lt;/ul&gt;
49110
I am writing a template for a views field in Drupal 8. How can I access the raw values of a multi-value field in views? I tried this but it doesn't work.  {% for i in 0.. row.field_color['#items']|length - 1 %} {{ row.field_color[i] }} {% endfor %}