Skip to content

p-for

PrunePy’s p-for directive allows you to create DOM elements by iterating through a list.

You can iterate over store values too but in this examples we only iterate on raw values.

Here’s a simple example of using it to create a list of colors based on an array :

index.html
<ul>
<template p-for="color in ['red', 'blue', 'black']">
<li p-text="color"></li>
</template>
</ul>

Iterate on a range

index.html
<ul>
<template p-for="i in range(3,7)">
<li p-text="i"></li>
</template>
</ul>

Iterate on dict

index.html
<ul>
<template p-for="key,value in {'taste':'peperonni', 'size': 'XL'}.items()">
<li>
<span p-text="key"></span>
<span> - </span>
<span p-text="value"></span>
</li>
</template>
</ul>