Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added compact helper #603

Merged
merged 10 commits into from
Mar 5, 2019
Merged

added compact helper #603

merged 10 commits into from
Mar 5, 2019

Conversation

josephmancuso
Copy link
Member

@josephmancuso josephmancuso commented Mar 2, 2019

it is very repetitive when you want to have a variable name and you want to send a variable to the view with the same name. This may look something like this:

def show(self, view: View):
    posts = Post.all()
    users = User.all()
    return view.render('some.template', {'posts': posts, 'users': users})

now you can do:

from masonite.helpers import compact

def show(self, view: View):
    posts = Post.all()
    users = User.all()
    return view.render('some.template', compact(posts, users))

You can also pass in a dictionary which will update accordingly:

from masonite.helpers import compact

def show(self, view: View):
    posts = Post.all()
    users = User.all()
    user_blogs = Blog.where('user_id', 1).get()
    return view.render('some.template', compact(posts, users, {'blogs': user_blogs}))

@coveralls
Copy link

coveralls commented Mar 2, 2019

Coverage Status

Coverage increased (+0.09%) to 87.813% when pulling 863afd7 on add-compact-helper into ccf34c0 on master.

@vaibhavmule
Copy link
Contributor

Do you mean?
posts and users without stirng?
return view.render('some.template', compact(posts, users))

@josephmancuso
Copy link
Member Author

#602

@josephmancuso josephmancuso merged commit bb32687 into master Mar 5, 2019
@nioperas06
Copy link
Contributor

Is this available in 2.1.19?

@josephmancuso
Copy link
Member Author

no it will be in 2.1.20. I can release now if you like :)

@nioperas06
Copy link
Contributor

🙌

@josephmancuso
Copy link
Member Author

released

@josephmancuso josephmancuso deleted the add-compact-helper branch April 1, 2019 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants