pogidude Posted July 26, 2013 Share Posted July 26, 2013 I'm working with inputfields and saw in core/InputfieldWrapper.php file the add(), append() and other related methods. I tested both and came out the same: $modules = $this->modules; //$this->setFuel('processHeadline', 'Content Flow Here'); $form = $modules->get('InputfieldForm'); $field = $modules->get('InputfieldMarkup'); $field->label = $this->_('My Markup'); $field->attr('value', '<h4>Not my markup content</h4>'); $field2 = $modules->get('InputfieldMarkup'); $field2->label = $this->_('Second Markup'); $field2->attr('value', '<h4>Not my markup content</h4>'); $wrapper = new InputfieldWrapper(); $wrapper->attr('title', 'Wrap Title'); $wrapper->attr('description', 'Wrapp'); $wrapper->add($field); $wrapper->append($field2); $form->append($wrapper); //$form->append($field2); return $form->render(); so, my question is, what's the difference between the two? and when should I use one over the other? Link to comment Share on other sites More sharing options...
Wanze Posted July 26, 2013 Share Posted July 26, 2013 They're both doing the same. There are also other methods available: prepend(Inputfield $item) : Adds your Inputfield on the first position insertBefore(Inputfield $item, Inputfield $existingItem) : Add your Inputfield before the Inputfield $existingItem insertAfter(Inputfield $item, Inputfield $existingItem) : Add your Inputfield after the Inputfield $existingItem 1 Link to comment Share on other sites More sharing options...
pogidude Posted July 26, 2013 Author Share Posted July 26, 2013 yeah which is what confused me.. since they both added the inputfield at the *end*. so you're basically saying I just take my pick between the two? Link to comment Share on other sites More sharing options...
Wanze Posted July 26, 2013 Share Posted July 26, 2013 so you're basically saying I just take my pick between the two? Jep Link to comment Share on other sites More sharing options...
ryan Posted July 28, 2013 Share Posted July 28, 2013 We have append() for consistency with jQuery. I also like the team of prepend/append naming (it sure beat's PHP's unshift/push terminology). But I also think the term "add" is ultimately more friendly, especially when talking about adding an item to a group of items. As a result, I tend to use add() when adding items and append() when moving things around. Ultimately they do the same thing, but one may be more readable than the other depending on the context. Use whatever you prefer. Link to comment Share on other sites More sharing options...
pogidude Posted July 28, 2013 Author Share Posted July 28, 2013 Thank you Wanze and thank you Ryan Yes, I did notice that "add()" and "append()" both resulted in the same thing so I wanted to make sure that there was no implementation difference between the two Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now