Twig create array and place them in specific places - arrays

I'm pretty new to Twig and can't figure one thing out!
I'm trying to create a homepage where in different spots images need to be placed. I know this can be done by executing a function where an image need to be placed. Problem is that I have to do that 7 times on one page.
So my question is if you can create some sort of array and then get the results from the array in the appropiate spots.
See below
Let's say I want to place an image in A,D,E,G. What would be the quickest way to accomplish that? What I already can do is
{% for product in products %}
{% endfor %}

Related

AngularJS randomly show data bug

Here is my running code in Plunker
First issue I want to solve is: I want to randomly show the data. For my case, I have two questions. One is "Do you like Foo", another one is "Do you like Bar".
When I reload the page, I want these questions to show up randomly. For example, maybe "Do you like Foo" show first this time. But when I reload the page, "Do you like Bar" show first.
I made a custom random filter as below, but this will cause bug that "I cannot see the check symbol when I check the checkBox"
$scope.random = function () {
return 0.5 - Math.random();
}
Another in my line 14 of my Plunker, I added <div ng-repeat="item in questions | orderBy: random">
Updated: Based on comment, I created another post for my another.
Instead of picking up questions randomly, you can try shuffling your array before showing any question on your page.
This way, the array's elements will be randomly indexed, and you won't need to run the random function for each question.
Here is a post to help you with shuffling the array using JavaScript. Alternatively, you can also use Lodash's Shuffle function.

Symfony2 - Generate input fields based on entity

I'm having a trouble with creating a dynamic form in Symfony2.
What i wanna do is to register a collection of text field which are generated from an entity.
I dont know where to start exactly but here's a kinda of pseudo-code of what im trying to do :
in my view :
{# list_type_url are retrieved from DB #}
{% for url in list_type_url %}
<input type="text" name="link[{{ url.name }}]">
{% endfor %}
I started in my form builder with this :
$builder->add('link', CollectionType::class)
but I dont know how to link the array in the view with the form.
Maybe Im thinking it wrong ?
EDIT:
I edit the post to make things clearer :
the list_type_url variable is coming from an another entity. Let's says it is named UrlType, in which I can create a type of url.
Then in an another entity, imagine "Contact", i want to be able to add all the type of existing url.
so concretely, I could create 3 types of url or more (lets say top, middle, bottom) and in my contact form, i have to display those 3 types and fill them with different urls and i should be able to retrieve each of the types for a particular contact.
I've also readed how to dynamically modify forms but I really don't see how to use it with my problem
I hope i get more clearier

How can I make nested dom-repeat have independent loop variables?

I need to bind two nested dom-repeats. Something like:
foreach product in some_query
list all product images
So i setup a first dom-repeat which does the product query and inside I launch another query to get the images and another dom-repeat will list them. The result is that all the products listed end up with the same images.
The product names list correctly and all the queries launch correctly also but, in the end, all the image blocks are identical.
I tried with Polymer.templatize and stamp the inner template and also using some elements like iron-list but the result is always the same.
I created a "small" example here
https://jsbin.com/didijo/edit?html,js,output
How can I achieve this?
Let me know if you need any additional information.
Thanks for any help.
I revisited this issue now as I couldn't wait any longer. I got it working by creating a new web component and putting the ajax call and the output inside the component. Something like this:
<template is="dom-bind">
<get-indexes indexes="{{indexes}}"></get-indexes>
<template is="dom-repeat" items='[[indexes]]' as="firstlevel">
<strong>[[firstlevel]]</strong><br>
<get-rowdetails idx="[[firstlevel]]"></get-rowdetails>
</template>
</template>
Look for me if you need help or more details.

Salesforce.com visualforce between 2 objects

In salesforce I need to create a visualforce page that includes the fields of 2 objects. The first object is the QUOTE object. The second objects is a custom object with several fields.
I want to create a visualforce page that shows the records of both QUOTE and the new object. Can I do this without creating a custom controller? If no any hints on the code for this new controller?
Can I do calculations between fields in a visualforce page?
Ideally I want this page to appear as soon as the QUOTE is set to ACCEPTED
1: You can't do this without a custom controller unfortunately, unless one object is related to the other and you're just happy displaying it as a related list on the parent object's page. For calculations you could use rollup summaries for some basic sums etc..
As for a custom controller, have a look at field sets for a super easy way to get fields into a VF page, you essentially configure groups of fields on your objects and then you can stick those groups onto a page with minimal markup.
2: For fields with complex calculations you'll want to do the sums in the controller and then expose the results through variables onto the page in the usual manner.
3: Not really possible without creating a custom edit page in the first place — you'd be better off having a button on the quote page to open up the Visualforce page, that page can simply display an error if the quote is not yet accepted. There are some other alternatives that might work though, like using a forumla field to generate a link to the page when the status is as you desire.
I'm happy to elaborate on any of this, but the fact that you're asking about number 2 would suggest to me that you don't have much experience developing on the platform (not a dig, just an observation), so unless you're comfortable coding in other environments you could find this quite tricky. That said, you're on stackoverflow so I'm thinking you probably know a little about coding at least!

Reverse query on django extended user profile

I have extended User via AUTH_PROFILE_MODULE to include a ManyToMany field to Projects the user is involved in.
I want to reverse the relationship, and get the Users associated with a given Project.
My users have profiles (I've successfully returned them with related_projects = u.profile.projects).
related_users = project.userprofile_set.all() is giving me something - {% for user in related_users %} {{ user }} {% endfor %} yields User Profile for: richlyon. But I can't get {{ user }} to yield any fields. I've tried {{ user.username }}.
Question: am I going about this the wrong way? And if I'm not, how do I get field information out of a reverse relationship on an extended User profile?
Thanks as always for your time.
Your 'profile' object is not a User, nor is it extending User (in an object-oriented sense). Rather, it's a separate model that has a ForeignKey to a User.
User > Profile > Projects
In the code you posted, it looks like you're expecting a User object to be returned from the project.userprofile_set.all() query set. However, these are going to be your intermediate profile objects from which you can then access the user.
Something like this:
related_profiles = project.userprofile_set.all()
{% for profile in related_profiles %}
{{ profile.user.username }}
{% endfor %}

Resources