donators

n@work Internet Informationssysteme GmbH
Your ad here

supported by

 TYPO3 Hamburg
 TYPO3 Anbieter

Advertising

How-to use templates in Eclipse

By: Thomas

13.06.08 13:54 Age: 121 days

Hi,

I know that this might be very scary for some people. But I recognized that not many developers work with snippets. To be honest I was one of them. I thought it is much faster to copy and paste the needed stuff from other files. Well, maybe it is faster but that's not the point.

Since my tries with Komodo Edit I used abbreviations for the first time. It's a very handy tool if you write the same things over and over again in many files. (And bigger extensions have a lot of files in the most cases.) You just enter your code and put some placeholders here and there and than you can use it with a keyword and key combination. Can be useful for any kind of code you use more than one time week.

In my Komodo Edit post I wrote, that I will stay with Eclipse as my editor. Because Eclipse is such a big product it supports templates too of course. It took my some minutes and a chat with Robert (who really impressed me with the templates in his presentations! ;-) ) to figure out how you can use this feature on OS X.

As you can see on the first screenshot you have to go to Eclipse preferences to the page "keys" und "General". In the list of key bindings search for "Content Assist" and than change the key binding as you like. In my case I had to change it because other programs registered for that combination already.

 

When did that you can define some templates. I assume that you have PDT installed! Go to page PHP -> Templates and create a new template. Now you write your PHP code as usual. You can add some placeholders in the form ${nameOfPlaceholder}. The clue with that placeholders is, that you can use them several times in the same template. When you fill the first placeholder with data all others with the same name will be substituted automatically.

There are some predefined placeholders like ${year} that prints the current year without the need to type it yourself. After all I really like this feature and I'm sure I'll use it much more in the future.

By the way, you can export your set of templates and share them with others. A set of FLOW3 templates are available here.

I also made a short demo video how a template could be used:

 

Greets,
Thomas

11 Responses to “How-to use templates in Eclipse”

#1: Ingo commented on Friday, 13-06-08 15:21

Gravatar: Ingo

Do you want to share your templates maybe? =)


#2: Thomas Hempel commented on Friday, 13-06-08 16:03

Gravatar: Thomas Hempel

I'm not sure if it's worth the download for getting two small templates. ;-) But maybe one can create a forge rep for this. ;-)

Greets,
Thomas


#3: Roy Ganor commented on Friday, 13-06-08 21:54

Gravatar: Roy Ganor

Looks like a very usefull information for all Eclipse and PDT users!

do you mind to add it as a tutorial to the following wiki page:
http://wiki.eclipse.org/PDT/TUTORIALS


#4: Thomas commented on Friday, 13-06-08 22:36

Gravatar: Thomas

Hi Roy,

thanks for adding the link! :-)


Greets,
Thomas


#5: Semseo commented on Thursday, 19-06-08 01:25

Gravatar: Semseo

thanks for the very usefull information for all Eclipse and PDT users!


#6: Karpacz commented on Thursday, 26-06-08 19:13

Gravatar: Karpacz

Sweet Blog!


#7: Karpacz Noclegi commented on Tuesday, 08-07-08 11:27

Gravatar: Karpacz Noclegi

Very Nice Blog!


#8: G?ry commented on Saturday, 12-07-08 11:15

Gravatar: G?ry

Good blog. Nice articles. It's very interesting


#9: Tworzenie stron commented on Monday, 28-07-08 19:37

Gravatar: Tworzenie stron

Oh, it's good advice. Your article is very helpfull. Thanks


#10: Mateus commented on Monday, 15-09-08 17:58

Gravatar: Mateus

Hello, how i configure specified ${nameOfPlaceholder} ? Thanks for help.


#11: neochung commented on Sunday, 28-09-08 06:14

Gravatar: neochung

As you mentioned above, " it is much faster to copy and paste the needed stuff from other files."
This really helps for Big project management.
thanks a lot.


Leave a Reply

You have to activate JavaScript to post comments!

Calendar

June 2008
M T W T F S S
« May   Jul »
 01
0203045678
09101112131415
16171819202122
23242526272829
30  

Latest comments

  • Peter

    Take a look here for a discount for the book: http://typo3bloke.net/post-details/my_typo3_extension...

  • Robert

    Well, one can live only so long by basically exploiting oneself, so I think it's very understood in...

  • neochung

    As you mentioned above, " it is much faster to copy and paste the needed stuff from other files." ...

  • reto

    Thanks for your great work and good luck!

  • Anoop

    ++ Michael Cannon! Thanks Thomas for all your work, don't disappear! I read your blog regularly ...

Advertising